For Python 2
print 'hello'
For Python 3
print('hello')
# print 'hello'
Python is dynamic typed.
x = 54
y = 5.4
s = 'hello'
b = True
print 'x: {}'.format(x)
print '{s} {x}'.format(s=s, x=x)
print '{sakura} {xmen}'.format(sakura=s, xmen=x)
a = [1, 234, 45, 45]
b = ['hello', 'python']
a[-1]
a[0:2]
s[0:4]
a[1] = a[1] - 1
b.append('world')
len(a)
a.count(456)
234 in a
d = {'key': 'Value', 'last': 'Suzuki'}
d['last']
d['first'] = 'Alto'
t = (100, 200)
if x == 54:
print 'yes'
elif x == 5.4:
print 'no'
else:
print 'NO'
while x == 54:
print 'yes'
for item in a:
print item
z += 1
try:
z += 1
except:
z = 0
z += 1
# Replace space in string with underscore
s = 'sublime text'
w = s.split()
s = '_'.join(w)
print s
# Split string by symbol
s = ' this ;is; so; fun '
w = s.split(';')
# ... and also cleanup the whitespaces
w = []
for r in s.split(';'):
w.append(r.strip())
w = [r.strip() for r in s.split(';')]
# Make a copy of the list without duplicated numbers
a = [1, 2, 3, 3, 5, 5, 6]
b = []
...
# Count number of duplicate of each unique number in the list
a = [10, 10, 20, 20, 10, 20, 10, 30, 30, 40]
# Expected result: count = {10: 4, 20: 3, 30: 2, 40: 1}
s = 'label_a,label_b,label_c'
with open('test.txt', 'w') as f:
f.write(s + '\n')
with open('text.txt', 'r') as f:
for line in f:
print line