Monday, May 27, 2019

Python Object and Datastructure Basics:Strings,Print Formatting

Python Object and Datastructure Basics:Strings,Print Formatting
jupyter notebook
print("Hello")
Hello

Comment the code #
This is actually a mark down cell wont execute  ==>mark down
l=[1,2,3,4]

l.tab(shift+tab==> show the comment)
comment the code==>ctrl+forward slash

a=1
type(a)
int

a=0.2
type(a)
float

#Order of the Execution
PEMDAS==paranthaesis,exp,mul,div,add,sub

a,b=1,2
print("Hello \t how are you")
Hello   how are you

#Concatenation:
s='string'+'new string'
print(s)
stringnew string

#Repeat the string:
letter='A'
letter *5
'AAAAA'

#String Indexing:
s='Hello how are you'
s[0]===>'H'
s[0:4]==>'Hell'
s[starting index:ending index(not including):step size]

s[6:9]=>'how'
s[-1]=>'u'
s[-2]=>:'o'
s[:]=>'Hello how are you'
s[0:10:2]=>'Hlohw'

reverse the string:
s[::-1]  =>'uoy era woh olleH'
s[::-2]  =>'uyeawholH'

len(s)==>17
s[0]='K'
s='her'

#string is immutable
id(s)-->memory id (70477056L)
a=10
print('a value is',a)
('a value is', 10)
a=10
print('a value is',format(a))

s='Hello how are you'
s.count('o')==>3
s='Hello how are you'

s.isdigit()==>False






No comments:

Post a Comment

Python Challenges Program

Challenges program: program 1: #Input :ABAABBCA #Output: A4B3C1 str1="ABAABBCA" str2="" d={} for x in str1: d[x]=d...