0% found this document useful (0 votes)
3 views5 pages

Python

The document provides an overview of various Python programming concepts including typecasting, arithmetic operations, string functions, format specifiers, data structures (lists, sets, tuples, dictionaries), default and keyword arguments, arbitrary arguments, and variable scoping. It includes code examples for each concept to illustrate their usage. Overall, it serves as a concise guide for beginners to understand fundamental Python programming techniques.
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)
3 views5 pages

Python

The document provides an overview of various Python programming concepts including typecasting, arithmetic operations, string functions, format specifiers, data structures (lists, sets, tuples, dictionaries), default and keyword arguments, arbitrary arguments, and variable scoping. It includes code examples for each concept to illustrate their usage. Overall, it serves as a concise guide for beginners to understand fundamental Python programming techniques.
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

Python

1-Typecasting : the process of converting one data type to another :

typpe=type(name)

print(typpe)
return :<class ‘str’>

age= 20
age=str(age)

age+="1"
print(age)
return :201

2-Arithmetic operations : some arithmetic op that can be halpfull

x = 3.14
y = 4
z = 7
P = pow(z,x)
R = round(x)
M = max(x,y,z)
A = abs(y)

Other arithmetic functions extended from the library math :

import math

x=9.9
print([Link])
print(math.e)
result=[Link](x)
result=[Link](x)
result=[Link](x)

print(result)

3-Some string functions :

name = input("enter your name")


phone_number=("enter you phone number")
name_lenght=len(name) #The lengh
position=[Link]("n") #position of a letter
reverse_position=[Link]("n") #position of a letter but in
reverse
up=[Link]() # make every letter an uppercase
low=[Link]() # make every letter a lowercase
digit=[Link]() # return true if the string is constructed
with only digit
alpha=[Link]() # return true if the string is constructed
with only alphas

count=phone_number.count("-")
replace=phone_number.replace("-","_")
print(position)

4-Some Format specifiers:

price1=3.1476
price2=100.2833
price3=12843.293
print(f"Price 1 is {price1:<10}")
print(f"Price 2 is {price2:f2}")
print(f"Price 2 is {price2:+}")

4-Lists Set Tuple:

Note: to display all methods of a function use dir()


Lists = [] ordered and changeable , Duplicates ok
Its functions : such as : insert() , add() , remove() , clear() , sort() , reverse() , index()
……
Set = {} unordered and immutable , but add/remove ok ,No duplicates
Tuples = () ordered and unchangable , Duplicates ok , Faster
5-Dictionary:

A collection of {Key:value} pairs ordered and changeable, No duplicates

Capitals={"USA":"Wachingtone",
"India":"New delhi",
"China":"Beijing",
"Russia":"moscow"}

print([Link]("USA"))
print(Capitals)
if [Link]("Algeria"):
print("there is")
else :
print("there is none")
# print(dir(Capitals))
keys = [Link]()
for key in keys:
print(key)
values= [Link]()
for value in values :
print(value)
item = [Link]()
for key,value in item :
print(key,value)

6-Default Argument:

def Count_Price(price,discount=0,taxes=0.05):
return price-(price*discount)+(price*taxes)

print(f"the price of what you have bought is


{Count_Price(500)}")
7-Keyword Argument:

def Hello(greeting,title,first_name,last_name):
return greeting + title + first_name +last_name

print(Hello("hello ",first_name="spongbob
",last_name="sqare ",title="ms "))

8-Arbitary Argument:

# *arg = allow you to pass many non keys arguments


# **kwargs = allow you to pass many keywords arguments
def calcul(*nums):
total=0
for num in nums:
total+=num
print(total)
calcul(1,2,3,4,5,9)
########################
def print_add(**kwarks):
for mftah,item in [Link]():
print(f"key: {mftah} value:{item}")

print_add(address="9a3 al hamor"
,street="the one that get to see the first"
,house="bob's house")

9-variable scoping in python:


#variable scope : whera the
variable is visible and
accessible
#scope resolution
:(LEBG)local -> enclosed ->
global -> build in

You might also like