Python Intro (Ymca)
Python Intro (Ymca)
Rohan saini
Mtech-
CSE
Python Introduction
What is Python?
• Python is a popular programming language. It was created by Guido van
Rossum, and released in 1991.
• It is used for:
• web development (server-side),
• software development,
• mathematics,
• system scripting.
Python Variables:
a = 55
b = "Hello, World!“
Python Comments:
#This is a comment.
print("Hello, World!")
• Since Python will ignore string literals that are not assigned to a
variable, you can add a multiline string (triple quotes) in your code,
and place your comment Inside it:
• Eg.
"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")
Creating variables:
a = 10 # x is of type int
a = “Rohan" # x is now of type str
print(a)
• Type Casting
a = str(5) # a will be ‘5'
b = int(5) # b will be 5
c= float(5) # c will be 5.0
q=5
w = “Rohan"
print(type(q)) #checking the data type
print(type(w))
Case sensitive
a=4
A = "Sally"
#A will not overwrite a
Variable Names
• A variable can have a short name (like x and y) or a more descriptive
name (age, carname, total_volume). Rules for Python variables:A
variable name must start with a letter or the underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE are three
different variables)
x = 20 int
x = 20.5 float
x = 1j complex
x = range(6) range
x = True bool
There are three numeric types in Python:
• int
• float
• complex
Eg.
x = 5 # int
y = 6.8 # float
z = 2j # complex
print(type(x))
print(type(y))
print(type(z))
Python Casting
Casting in python is therefore done using constructor functions:
Floats:
• x = float(1) # x will be 1.0
y = float(2.8) # y will be 2.8
z = float("3") # z will be 3.0
w = float("4.2") # w will be 4.2
Strings:
• x = str("s1") # x will be 's1'
y = str(2) # y will be '2'
z = str(3.0) # z will be '3.0'
Strings