0% found this document useful (0 votes)
5 views3 pages

Python Basics: Data Types & Variables

Uploaded by

guddi1594
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Python Basics: Data Types & Variables

Uploaded by

guddi1594
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Code for section "Getting Started with Python"

of the course "Python in Depth" by Deepali Srivastava

Keywords and Identifiers


>>> len
>>> print
>>> int
>>> print = 4
>>> print('Hello')

Python Data Types


>>>2+42
>>>5**671
>>>type(23)
>>>type(True)
>>>type(2.3)
>>>type('hi')
>>>type(None)
>>>bin(32)
>>>oct(32)
>>>hex(32)
>>>7e4
>>>7e-4
>>>int(12.3)
>>>int('100')
>>>int("two")
>>>int(True)
>>>int(False)

>>>str(100)
>>>str(3.6)

>>>float('3.45')
>>>float(3)

>>>int('FF', 16)
>>>int('0101', 2)

Variables

>>>id(34)
>>>id('hello')
>>>x=88
>>>type(x)

"Python in Depth" by Deepali Srivastava 1


>>> id(x)
>>>x = 'hello'
>>>type(x)
>>> id(x)
>>>a=6.7
>>>b=a
>>>c=b
>>>b
>>>c
>>>id(a)
>>>id(b)
>>>id(c)
>>>a=a+3
>>>a
>>>b
>>>c
>>id(b)
>>id(c)

Variables …. continued
>>>c=23
>>>a=b=c=c+10
>>>a
>>>b
>>>c

>>>x,y,z = 10, 1.6, 'hi'


>>>x
>>>y
>>>z

>>>del b
>>>b
>>>del x,y
>>>x
>>>y

Operators
>>>4+6
>>>1.2+4
>>>3**2
>>>16**0.5
>>>17/5
>>>17//5
>>>17%5
>>>x=3

"Python in Depth" by Deepali Srivastava 2


>>>y=4
>>>x<y
>>>x==y
>>>x!=y
>>>x>=y
>>>x==3 and y<6
>>>x>10 and y<6
>>>x>10 or y<6
>>>1<x<8
>>>1<x and x<8

>>>a = 123456789
>>>b = 123456789
>>>a is b
>>>id(a)
>>>id(b)
>>>a is not b
>>>a==b
>>>c=2
>>>d=2
>>>c is d
>>>e=1.5
>>>f=1.5
>>>e is f
>>>g='cat'
>>>h='cat'
>>>g is h

Input/output and Comments


print('Sunday', 'Monday', 8,9)
print('Sunday', 'Monday', 8,9, sep =':')
print('Sunday', 'Monday', 8,9, sep ='--')
print('Sunday', 'Monday', 8,9, sep ='')
print('Let us start programming', end = '..')
print('3 plus 5 is ', 3+5, end ='|')
print('Python is interesting')
print()
print()
print('Good Bye')
city = input()
print(city)
city = input('Enter city : ')
print('Welcome to', city)
salary = float(input('Enter salary : '))
salary += 100 #incrementing salary
print(salary)
x = int (input('Enter x : '))
print(x)

"Python in Depth" by Deepali Srivastava 3

You might also like