Say "Hello, World!" With Python:
a= "Hello World!"
print a
Output:
Hello World!
Getting Input:
a=raw_input()
print a
print a
Input:
gavaskar
Output:
gavaskar
Operations on String:
a,b=raw_input().split()
print a+b
print a,b
print a+b
print a,b
Input:
gokul kannan
Output:
gokulkannan
gokul kannan
Alternate String cases:
a=raw_input()
print a.upper()
print a.lower()
print a.title()
print a
print a.upper()
print a.lower()
print a.title()
print a
Input:
GavasKaR
Output:
GAVASKAR
gavaskar
Gavaskar
GavasKaR
Reverse the string:
a=raw_input()
print a[::-1]
print a[::-1]
Input:
Gavaskar
Output:
raksavaG
String Slicing:
a=raw_input()
print a[0:3]
print a[::]
print a[::2]
print a[::-2]
print a[0:5]
print a[0::]
print a[3::]
print a[0:3]
print a[::]
print a[::2]
print a[::-2]
print a[0:5]
print a[0::]
print a[3::]
Input:
gavaskar
Output:
gav
gavaskar
gvsa
rkaa
gavas
gavaskar
askar
Generate Random Number:
import random
print random.randrange(10)
print random.randrange(10)
Output:
6
Output:
3
Operators:
a=input()
b=input()
c=float(b)
print a+b
print a-b
print a*b
print a/b
print a/c
b=input()
c=float(b)
print a+b
print a-b
print a*b
print a/b
print a/c
Input:
4
3
Output:
7
1
12
1
1.33333333333
python-int-to-binary
n=input()
print "{0:b}".format(n)
Input:
10
Output:
1010
0 comments:
Post a Comment