Python [my code 😄😄😄]
PYTHON
k.Eswar krsihna
This is my persnol blog
Sourse: Coad With Harry
link: https://www.codewithharry.com
Why do i choose python??
python is easy to use while compared to java,c,c++.
Python is a preferred high-level,
server-side programming language for websites and mobile apps.
- Python is mainly used in
- Machine learning
- Web Development
- Data science
- Android app development
My first Pyhon Program
print("Hello World")
Basics of Python--
a = 32 # int
b = "Eswar" # string(it means text)
c = 45.32 # flot
d = 3.5 # flot
print(float(a + c))
# Shows decimal value also
print(int(a + d))
# it skips the decimal
Rules for creating variables
1.variable should start with a letter
or underscore
2.variable cannot start with a number
3.it can only contain alpha numeric
charactors
4.Variable names are case sensitive.
Eswar and eswar are two different
variables
Variables--
# variables are the storage containers
var1 = ("hello world")
var2 = ("Techno geeks guru")
print(var1)
print(var2)
print(var2)
print(5 * "subscribe\n")
#5 denotes the number of times and
#\n denotes end the line
# variables---
How to taske user input--
# User input---
print("enter your number")
_inputnumber = input()
print("you entered",_inputnumber)
# User input---
String slicing--
# string slicing---
mystr ="Hay google"
print(str(mystr)) # to print complete string
print(len(mystr)) # to know the length of the string
print(mystr [0]) # to print a particular latter in a string (H).
print(mystr [0:4]) # to print a particular word in string [0:4]
determines the range.
print(mystr [0:4:2]) # it prints [Hy]
print(mystr [:]) # it prints entire string
print(mystr.endswith ("google")) # True
print(mystr.count("o")) # counts how many times the letter occurs
print(mystr.capitalize()) # it capitalize the letter
print(mystr.find("google")) # it finds the word
print(mystr.upper()) # converts entire string converts to upper case
print(mystr.lower()) # converts entire string converts to lower case
print(mystr.replace("Hay","Ok")) # it replaces "Hay" with "Ok"
# string slicing---
Dictionary--
# 6. Dictionary---
# Dictionary is nothing but key value pairs
# Dictionary must use curly brases
d1 = {"Harry":"Burger", "Rohan":"Fish" }
print(d1)
print(d1["Harry"]) # prints Burger..
print(d1["Rohan"]) # prints Fish..
d2 = {"Eswar": {"breakfast":"idly" , "lunch":"Rise" , "dinner":"chapati"}}
d2 = {"karthik":"pani puri"} # we cam add items in middle
d2 = {"anirudh":"chapati"}
print(d2["Eswar"])
print(d2["Eswar"]["breakfast"])
print(d2["Eswar"]["lunch"])
print(d2["Eswar"]["dinner"])
print(d2.copy())
print(d2) # it includs karthi and anirudh
# Dictionary---
Sets--
# 7. Sets
s = set()
s_from_list = set([1, 2, 3, 4])
print(s_from_list)
print(type(s_from_list))
s.add(1) # set retain unique values
s.add(1) # skips the repited values
s.add(0)
s1 = s.union({1, 2, 3}) # union add in the existing set
s1 = s.intersection({1, 2, 3}) # intersection creats new set
print(s)
print(s1)
print(len(s)) # length of s
print(max(s)) # max number of s
print(min(s)) # min number of s
# sets
if, elif, else--
# 8. if,elif,else---
var1 = 5
var2 = 56
print("enter the number")
var3 = int(input())
'''
The elif statement allows you to check multiple expressions
for TRUE and execute a block of code as soon as one of the
conditions evaluates to TRUE.
'''
if(var3>var2): # don't forget colen[:]
print("Grater")
elif(var2==var3):
print("Equal")
else:
print("Smaller")
list1 = [1, 2, 3]
print(5 in list1) # tells if the given number is in the list or not
if (1 in list1):
print("yes it is in the list")
# if,elif,else---
Loops--
# Loops---
list1= ["Eswar", "Karthi","Anirudh"]
for item in list1: # prints total list of items/names in list1
print(item)
# print the list in the form of dictonary
list2= [["Eswar" , 90], ["Karthi" , 95],["Anirudh" , 98]]
dict1 = dict(list2) # it prints as a dictonary
print(dict1)
for item, num in list2:
print(item,"got", num) # add the string in every word in the list
items =[int,float,"Eswar",1,2,5,6,5,8,98,77,44,84,]
# print the numbers in the items which are grater than 6
for item in items: # items is the name of the list
if str(item).isnumeric() and item>6:
print(item)
# while loops
# it is used to print numbers in series example to print number 1 to 50
i =0
while(i<51):
print(i)
i = i + 1 # without this line 0 will be the result infinity times
# Loops---
Need some space
The Most venerable thing in the world is Human Brain
Comments
Post a Comment