107. Literals in Python with Code || String, Float, Boolean Literals Programming Tutorials

preview_player
Показать описание
Code:
a=0b1010 #binary literal
b=100 #decimal literal
c=0o310 #octal
d=0x12c #hexadecimal

int_1=10
int_2=99

#float
float_1=10.5
float_2=1.5e2
#complex
x=3.14j

print(a,b,c,d)
print(int_1,int_2)

print(int(float_1))
print(complex(int_2))

# string literals

a='''apple'''
b="""apple"""
c='apple'
d="apple"
#e=apple
print(a,b,c,d)

strings='This is python in spyderIDE'
char="C"
multiline_str="""this is a multiline string with more than one line."""
unicode=u'\u00dcnic\u00f6de'
raw_str=r'raw \n string'
print(strings,char,unicode,raw_str)

#Boolean
x=(1==True)

y=(1==False)
a=True +6
b=False+90

print('x is',x)
print('y is',y)

print('a:',a)
print('b:',b)

complex_number1=complex(1,2)
print(complex_number1)
complex_number2=(1.0+2j)
print(complex_number2)
#special literals

juice='available'
soup=None

def menu(x):
if x==juice:
print(juice)
else:
print(soup)
menu(juice)

menu(soup)
#Literal Collections

fruits1=('Banana','Apple','Strawberry')
fruits2=['Banana','Apple','Strawberry']
fruits3={'Banana','Apple','Strawberry'}
fruits={"1":"Banana", "2":"Apple", "3":"Strawberry"}

print(fruits)
Рекомендации по теме
welcome to shbcf.ru