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

Python 1 Class

Uploaded by

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

Python 1 Class

Uploaded by

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

Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.

1929 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
a=1
num1=1
num1
1
type(num1)
<class 'int'>
str1="hello world"
str1
'hello world'
str2="no of items"
num1=2
str2+str(num1)
'no of items2'
str2+""+str(num1)
'no of items2'
str1="no of item{}".format(str(num1))
str1
'no of item2'
str2="nUMBERS are {} and {}".format(str(1),str(2))
num1=2
num2=2
str2="Numbers are {} and {}".format(str(num1),str(2))
str2
'Numbers are 2 and 2'
'Numbers are 2 and 2'
'Numbers are 2 and 2'
str2="Numbers are {} and {}".format(str(num1),str(num2))
str2
'Numbers are 2 and 2'
str1="numbers are {1} and {0}".format(str(num1),str(num2))
str1
'numbers are 2 and 2'
num1=1;
num1=1
num2=2
str2="Numbers are {} and {}".format(str(num1),str(num2))
str2
'Numbers are 1 and 2'
str2="numbers are {1} and {0}".format(str(num1),str(num2))
str2
'numbers are 2 and 1'
str1="'Test'"
str1
"'Test'"
"'Test'"
"'Test'"
num1=3
num2=4
num1+num2
7
num2/num1
1.3333333333333333
num2//num1
1
list1=[1,2,3,4]
list1
[1, 2, 3, 4]
list1[0]
1
list1[3]
4
list1.append(5)
list1
[1, 2, 3, 4, 5]
list1.append(5,6)
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
list1.append(5,6)
TypeError: list.append() takes exactly one argument (2 given)

tuple1=(1,2,3)
tuple1
(1, 2, 3)
tuple1.append(5)
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
tuple1.append(5)
AttributeError: 'tuple' object has no attribute 'append'
tuple[1]=2
Traceback (most recent call last):
File "<pyshell#50>", line 1, in <module>
tuple[1]=2
TypeError: 'type' object does not support item assignment
set1=set(liat1)
Traceback (most recent call last):
File "<pyshell#51>", line 1, in <module>
set1=set(liat1)
NameError: name 'liat1' is not defined. Did you mean: 'list1'?
set1=(list1)
set1
[1, 2, 3, 4, 5]
list1.append(5)
list1
[1, 2, 3, 4, 5, 5]
set1=(list1)
set1
[1, 2, 3, 4, 5, 5]
set1=set(list1)
set1
{1, 2, 3, 4, 5}
array
list
tuples=for constant values
set=removes duplicate items
dictionary key and value pairs
dict1={}
dict1
{}
dict1['fruit']='apple'
dict1
{'fruit': 'apple'}
dict1['veggie']='cabbage'
dict1
{'fruit': 'apple', 'veggie': 'cabbage'}
dict1['veggie']
'cabbage'

You might also like