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

Pythin

The document discusses various Python concepts like data types, variables, operators, conditional statements, loops, lists, tuples, sets, dictionaries and functions. It explains that Python is case sensitive, does not require data types to be specified for variables, supports operators like arithmetic, comparison, logical and string functions like upper, lower, find, replace. It also introduces conditional statements like if-else, loops like while and for, various data structures like lists, tuples, sets, dictionaries and different types of functions in Python.

Uploaded by

Bhavya
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
48 views3 pages

Pythin

The document discusses various Python concepts like data types, variables, operators, conditional statements, loops, lists, tuples, sets, dictionaries and functions. It explains that Python is case sensitive, does not require data types to be specified for variables, supports operators like arithmetic, comparison, logical and string functions like upper, lower, find, replace. It also introduces conditional statements like if-else, loops like while and for, various data structures like lists, tuples, sets, dictionaries and different types of functions in Python.

Uploaded by

Bhavya
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 3

Python

->Case sensitive

->Print (yahan pe variable ka naam dalna hoga dabbe me)

->data type of variables do not need to be mentioned to define them.


example: age= 14.0 will store age as a float value only without defining the
variable

->Concatenation:
print ("Hello " + name)
here, name is a variable.

->Type conversion:
If there's a variable: old_age= 22
Python thinks of the number 22 as string "22". It happens with every variable.
So, if we want to convert it to a int character:
we write it as: int(old_age)
for float: float(old_age)
Matlab mila jula ke variable ke data type change krwane ka tareeka h kyun ki by
default string me leta hn values saare variable unless specified.

->Strings:
name= "Tony Stark"
Upper/lower case= name.upper/lower()
Find Substring= name.find('S') = returns index of S i.e., 5
Index: position starting from 0
Replace= name.replace("Stark", "Ironman")
In keyword= print("T" in name)= returns True

->Arithmetic operators:
print(5-2)
Add: +, Difference: -, Multiply: *, Divide: / (// to remove numbers after
decimal), Modulo: %, Power: **.
Minimise operations: +=, -=

->Comparison operators:
Returns boolean value (True, false)
>, <, <=, >=, ==, !=

->Logical Operators:
Returns Boolean value
or, and, not (true becomes false and vice-versa)

->if-else statement:
age= 19
if age>=18: (colon lagana hota h to show we're gonna write a block of statments)
print("You are an adult") [Indentation is really imp]
print("You can vote")

elif age<18 and age>3:


print("you are in school")

else:
print("child")

->Range:

->Loop:
1. While:
example:
i=1
while i<=5:
print(i * "*") (jitna i ka value utne stars print kr do)
i= i+1
2. For:
to print sequence. example:
for item in range(5):
print(item+1)

->List data type:


[] is used to make list data type.
data type might be different in the same data type.
index can be in negative as well. Ex: -1 means the last element
example:
marks=[95,96,98]
print (marks[1:3]) will print every item from index 1 to 7
operations in list:
- marks.append(99) here 99 will be appended to the list
- marks.insert(99) 99 start me chala jayega list ke
- print(len(marks)) gives the length of the list
while i< len(marks)
- marks.clear() clears the list

->break and continue:


break; breaks the loop when a particular value is reached
continue; example:
students=["ram", "shyam", "kishan", "radha", "radhika"]
for student in students:
if student=="kishan":
continue;
print (student)
this will print every name in the list accept for kishan

->tuple:
it's a list but immutable i.e., no changes can be made.
marks= (95,98,97,99)
print(marks.count(97)) 97 ka count de dega list me
print(marks.index(97))

->set:
marks= {95,96,97, 97, 97,98}
stores only unique value to agar ham set print krwayenge to 97 ek baar hi aayega
output me.
issme index ni hota to issko unorderd bolte hn, print karane ke liye ye code
likhenge:
for score in marks:
print(score)

->dictionary
key aur value ke pair me value store karta h
marks={"english":95, "chemistry":98}
print(marks["chemistry"])
marks["physics"]= 97; add hojayega physics ka marks dictionary me

->functions
1. Inbuilt function
2. Module function (related funtions and variables stored together for ex: math
module to be imported like: import math/ from math import sqrt (sirf funtion import
krne ke liye module se))
3. User-defined function
syntax:
def funtion_name(parameters):
example:
def print_sum(first, second):
print(first+second)

print_sum(1,2)

def print_sum(first, second=4): defualt value lene ke liye

You might also like