Saturday, December 8, 2018

String functions in Python

x=6
y=12

print('x==y =',x==y)

This prints false

print('x!=y =',x!=y)

True

print('x>=y =',x>=y)

False

print('x>y =',x>y)

False

print('x<=y =',x<=y)

True
print('x
True


s1='Python\nis\namazing'

Print(s1)

This one prints


Python
is
Amazing

rs1=s1.encode('unicode_escape').decode()
print(rs1)

This one prints Python\nis\namazing


s2='Python\tis\tamazing'

This one prints

 Python    is    amazing

rs2=s2.encode('unicode_escape').decode()
print(rs2)

This one prints

Python\tis\tamazing

s='INfinity'
print(len(s))
print((s).isalpha())
print((s).isdigit())
print((s).upper())
print((s).lower())
print((s).count('i'))
print((s).index('t'))

print('Infinity'.startswith("I"))  -- return true
print('Infinity'.startswith("i")) --false
print('Infinity'.endswith('y'))
print('Infinity'.endswith('Y'))

print(min(30,20,10)) --min
print(max(30,20,10)) --max

print(('a,b,c').split(","))
print(','.join(['a','b','c']))


x=5
y=2
print(x+y)
print(x-y)
print(x*y)
print(x/y)
print(x**y)
print(x%y)

No comments: