Chapter Thirteen : Parts of C++ to avoid

EXAMPLE 13.1 page no : 159

In [2]:
s = 'abc' #raw_input()
print s
abc

EXAMPLE 13.2 page no : 160

In [3]:
class DangerousString:
    def __init__(self,cp):
        pass
    
    def char(self):
        pass

hello = "Hello World!";
print hello # Works perfectly
print "%s"%hello
Hello World!
Hello World!

EXAMPLE 13.3 page no : 160

In [4]:
class EmcString:
    def __init__(self,cp):
        pass


s = "Hello World!";
print s 
Hello World!

EXAMPLE 13.4 page no :161

In [5]:
SIZE = 1024;
print SIZE
1024

EXAMPLE 13.5 page no : 162

In [6]:
class X:
    class Color:
        green = 1
        yellow = 2
        red = 3

EXAMPLE 13.6 page no : 162

In [7]:
class X:
    maxBuf = 1024
    class Color:
        green = 1
        yellow = 2
        red = 3

EXAMPLE 13.7 page no : 162

In [8]:
def SQUARE(x):
    return x*x

i = SQUARE(3 + 4); 
print i
49

EXAMPLE 13.8 page no : 163

In [9]:
def square(x):
    return x * x;
c = 2;
d = square(c)
print d
4

EXAMPLE 13.9 page no : 163

In [10]:
"""
def SQUARE(x):
    return x*x
i = SQUARE("hello");
print i
"""
Out[10]:
'\ndef SQUARE(x):\n    return x*x\ni = SQUARE("hello");\nprint i\n'

EXAMPLE 13.10 page no : 163

In [11]:
#define Velocity int
#typedef int Velocity;
# Not recommended
Out[11]:
'\nEXAMPLE 13.10 page no : 163\nHow to define synonyms for a type\nNote : Python doesnot have synonyms for type as we do not have to explicitely \ndeclare variables.\n'

EXAMPLE 13.11 page no : 164

In [12]:
def printFruits(fruits,size):
    for i in range(size):
        print fruits[i] 
In [ ]: