Python
what is data type ?
to declaring of a variable is called data type
another words to declare the data what type of the data it is !
data types ?
Text Type: | str |
Numeric Types: | int , float , complex |
Sequence Types: | list , tuple , range |
Mapping Type: | dict |
Set Types: | set , frozenset |
Boolean Type: | bool |
Binary Types: | bytes , bytearray , memoryview |
None Type: | NoneType |
CODE FOR LIST SLICING:
------------
word=input('what is word?:')
print(word[1::2])
------
input: rhaajrui
output :HARI
---------------
where 1=index of word
2= after second letter will be print at everytime
SECOND ONE
word='rhaajrui'
print(word[1::2])
output:hari
CODE FOR REVERSING OF A STRING:
----------------
word=input('what is word?:')
print(word[::-1])
------
input: IRAH
output :HARI
---------------
CODE FOR STRING FORMAT:
name='krishna'
age='18'
sex= 'male'
print(f'the age of {name} is {age} and he is {sex}')
OUTPUT: the age of krishna is 18 and he is male
SECOND ONE
name='krishna'
age='18'
sex= 'male'
print(name ,age ,sex)
print(f'the age of {name} is {age} and he is {sex}')
print('the age of '+name+' is '+age+' and he is '+sex)
OUTPUT:
krishna 18 male
the age of krishna is 18 and he is male
the age of krishna is 18 and he is male
-------------------------
Comments
Post a Comment