0% found this document useful (0 votes)
12 views10 pages

Python Programming Basics: Data Types

The document contains a series of programming examples across various topics including lists, tuples, sets, dictionaries, object-oriented programming, NumPy, pandas for exploratory data analysis, data visualization with Matplotlib and Seaborn, and file handling. Each section includes multiple programs demonstrating basic operations and functionalities associated with each topic. The examples are concise and illustrate fundamental concepts in Python programming.

Uploaded by

Relaxing world
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)
12 views10 pages

Python Programming Basics: Data Types

The document contains a series of programming examples across various topics including lists, tuples, sets, dictionaries, object-oriented programming, NumPy, pandas for exploratory data analysis, data visualization with Matplotlib and Seaborn, and file handling. Each section includes multiple programs demonstrating basic operations and functionalities associated with each topic. The examples are concise and illustrate fundamental concepts in Python programming.

Uploaded by

Relaxing world
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

LIST

Program 1:
numbers = [1, 2, 3, 4, 5] print(numbers)

Program 2:
numbers = [10, 20, 30] [Link](40) print(numbers)

Program 3:
numbers = [5, 2, 8, 1] [Link]() print(numbers)

Program 4:
numbers = [1, 2, 3, 4, 5] print(sum(numbers))

Program 5:
numbers = [1, 2, 3, 2, 1] print([Link](2))

Program 6:
numbers = [1, 2, 3, 4, 5] numbers[2] = 100 print(numbers)
TUPLE

Program 1:
t = (1, 2, 3) print(t)

Program 2:
t = (10, 20, 30) print(t[1])

Program 3:
t = (1, 2, 3, 4, 5) print(len(t))

Program 4:
t1 = (1, 2) t2 = (3, 4) print(t1 + t2)

Program 5:
t = (1, 2, 2, 3) print([Link](2))

Program 6:
t = (1, 2, 3) a, b, c = t print(a, b, c)
SET

Program 1:
s = {1, 2, 3} print(s)

Program 2:
s = {1, 2, 3} [Link](4) print(s)

Program 3:
s = {1, 2, 3, 2} print(s)

Program 4:
a = {1, 2, 3} b = {3, 4, 5} print(a | b)

Program 5:
a = {1, 2, 3} b = {2, 3, 4} print(a & b)

Program 6:
s = {1, 2, 3} [Link](2) print(s)
DICTIONARY

Program 1:
student = {'name': 'Nouman', 'age': 20} print(student)

Program 2:
student = {'name': 'Nouman', 'age': 20} print(student['name'])

Program 3:
student = {'name': 'Nouman', 'age': 20} student['age'] = 21 print(student)

Program 4:
student = {'name': 'Nouman', 'age': 20} for k,v in [Link](): print(k, v)

Program 5:
student = {'name': 'Nouman', 'grade': 'A'} print([Link]('grade'))

Program 6:
student = {'id': 1, 'name': 'Nouman'} del student['id'] print(student)
OBJECT ORIENTED PROGRAMMING (OOP)

Program 1:
class Car: def __init__(self, brand): [Link] = brand car1 = Car('Toyota')
print([Link])

Program 2:
class Car: def drive(self): print('Driving') car1 = Car() [Link]()

Program 3:
class Student: def __init__(self, name): [Link] = name s = Student('Nouman')
print([Link])

Program 4:
class Person: def __init__(self, name): [Link] = name def greet(self):
print('Hello', [Link]) p = Person('Nouman') [Link]()

Program 5:
class Animal: def sound(self): print('Animal sound') class Dog(Animal): def
sound(self): print('Bark') d = Dog() [Link]()

Program 6:
class Bank: balance = 0 def deposit(self, amount): [Link] += amount def
show(self): print('Balance:', [Link]) b = Bank() [Link](500) [Link]()
NUMPY

Program 1:
import numpy as np arr = [Link]([1,2,3]) print(arr)

Program 2:
import numpy as np arr = [Link](5) print(arr)

Program 3:
import numpy as np arr = [Link](1,10,2) print(arr)

Program 4:
import numpy as np arr = [Link]([1,2,3,4]) print('Mean:', [Link](arr))

Program 5:
import numpy as np arr = [Link]([[1,2],[3,4]]) print('Reshape:', [Link](4,))

Program 6:
import numpy as np arr = [Link]([[1,2],[3,4]]) print('Transpose:', arr.T)
EXPLORATORY DATA ANALYSIS (PANDAS)

Program 1:
import pandas as pd data = pd.read_csv('[Link]') print([Link]())

Program 2:
import pandas as pd data = pd.read_csv('[Link]') print([Link]())

Program 3:
import pandas as pd data = pd.read_csv('[Link]') print([Link]())

Program 4:
import pandas as pd data = pd.read_csv('[Link]') print([Link]().sum())

Program 5:
import pandas as pd data = pd.read_csv('[Link]')
print(data['column_name'].value_counts())

Program 6:
import pandas as pd data = pd.read_csv('[Link]') print([Link]())
DATA VISUALIZATION WITH MATPLOTLIB

Program 1:
import [Link] as plt [Link]([1,2,3],[2,4,6]) [Link]()

Program 2:
import [Link] as plt x=[1,2,3] y=[2,4,1] [Link](x,y) [Link]()

Program 3:
import [Link] as plt x=[10,20,30] [Link](x) [Link]()

Program 4:
import [Link] as plt x=[1,2,3,4] y=[10,20,15,25] [Link](x,y)
[Link]()

Program 5:
import [Link] as plt [Link]([1,2,2,3,3,3,4,4,4,4]) [Link]()

Program 6:
import [Link] as plt x=[1,2,3,4] y=[10,20,15,25] [Link](x,y,marker='o')
[Link]('Line Graph') [Link]()
DATA VISUALIZATION WITH SEABORN

Program 1:
import seaborn as sns import pandas as pd
data=[Link]({'A':[1,2,3],'B':[10,20,30]}) [Link](x='A',y='B',data=data)

Program 2:
import seaborn as sns sns.set_theme(style='whitegrid') tips=sns.load_dataset('tips')
[Link](x='total_bill',y='tip',data=tips)

Program 3:
import seaborn as sns data=sns.load_dataset('iris') [Link](data,hue='species')

Program 4:
import seaborn as sns data=sns.load_dataset('iris')
[Link]([Link](),annot=True)

Program 5:
import seaborn as sns data=sns.load_dataset('tips')
[Link](x='day',y='total_bill',data=data)

Program 6:
import seaborn as sns data=sns.load_dataset('tips')
[Link](x='day',y='total_bill',data=data)
FILE HANDLING

Program 1:
with open('[Link]','w') as f: [Link]('Hello Nouman')

Program 2:
with open('[Link]','r') as f: print([Link]())

Program 3:
with open('[Link]','a') as f: [Link]('\nNew line added')

Program 4:
with open('[Link]','r') as f: lines=[Link]() print(lines)

Program 5:
try: with open('[Link]','r') as f: print([Link]()) except FileNotFoundError:
print('File not found')

Program 6:
with open('[Link]','w') as f: for i in range(5): [Link](f'Line {i+1}\n')

You might also like