Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Python Programs to practice in lab

The document contains Python programs for practicing basic programming concepts, including variable display, area calculation of a rectangle, and data types. It provides examples of using integers, booleans, lists, tuples, sets, NoneType, and dictionaries. Each example includes code snippets and their corresponding outputs.

Uploaded by

Simran Shaikh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python Programs to practice in lab

The document contains Python programs for practicing basic programming concepts, including variable display, area calculation of a rectangle, and data types. It provides examples of using integers, booleans, lists, tuples, sets, NoneType, and dictionaries. Each example includes code snippets and their corresponding outputs.

Uploaded by

Simran Shaikh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Programs to practice in lab

Program 5-1 Write a program to display values of variables in Python.


message = "Keep Smiling"
print(message)
userNo = 101
print('User Number is', userNo)

Output:
Keep Smiling
User Number is 101

Program 5-2 Write a Python program to find the area of a rectangle given that its length is 10
units and breadth is 20 units.
length = 10
breadth = 20
area = length * breadth
print(area)

Output:
200

Example 5.3
>>> num1 = 20
>>> id(num1)

Output:
1433920576 #identity of num1

Example 5.4
>>> num1 = 10
>>> type(num1)
Output:
<class 'int'>

>>> var1 = True


>>> type(var1)
Output:
<class 'bool'>

Example 5.5
#To create a list
>>> list1 = [5, 3.4, "New Delhi", "20C", 45]
#print the elements of the list list1
>>> print(list1)
Output:
[5, 3.4, 'New Delhi', '20C', 45]

Example 5.6
#create a tuple tuple1
>>> tuple1 = (10, 20, "Apple", 3.4, 'a')
#print the elements of the tuple tuple1
>>> print(tuple1)
Output:
(10, 20, "Apple", 3.4, 'a')

Example 5.7
#create a set
>>> set1 = {10,20,3.14,"New Delhi"}
>>> print(type(set1))
Output:
<class 'set'>

Example 5.8
>>> myVar = None
>>> print(type(myVar))
Output:
<class 'NoneType'>

Example 5.9
#create a dictionary
>>> dict1 = {'Fruit':'Apple',
'Climate':'Cold', 'Price(kg)':120}
>>> print(dict1)
{'Fruit': 'Apple', 'Climate': 'Cold',
'Price(kg)': 120}
>>> print(dict1['Price(kg)'])
Output:
120

200

You might also like