Python Kuppiya 01 - E19
Python Kuppiya 01 - E19
1
What is a programming Language
Program
Computer
Programmer
Programming Language
2
Why we learn python?
Use this link to download python --- > Download Python | Python.org
4
Using the Python Shell, IDLE and Writing
our FIRST Program
You can search for it by typing “IDLE” in the search box. Once it is found, click on
IDLE (Python ……) to launch it. You’ll be presented with the Python Shell shown
below
>>> 5+3
>>> print("Hello World")
5
To create a Python script
To create a Python script, click on File > New File in the top menu of our Python
Shell.
6
How to use comment in python
#This is a comment
#This is also a comment
#This is yet another comment
print("Hello World")
Alternatively, we can also use three single quotes (or three double
quotes) for multiline comments, like this:
'''This is a comment
This is also a comment
This is yet another comment
'''
print("Hello World")
7
What are variables?
Variables are names given to data that we need to store and manipulate in our
programs.
This is equivalent to
userAge = 30
userName = ‘Peter’
8
Naming a Variable
A variable name in Python can only contain letters (a - z, A - Z), numbers or
underscores (_).
Eg:- user_Name , userName, userName2, _userName
But first character cannot be a number.
Eg :- 2username
There are some reserved words that you cannot use as a variable name
because they already have preassigned meanings in Python.
Eg :- if, else, while, in, or
variable names are case sensitive. username is not the same as userName
9
Basic Operators
01. Arithmetic Operation - Arithmetic operators are used to
perform mathematical operations like addition, subtraction,
multiplication and division.
< Less than: True if left operand is less than the right x<y
>>> a=13
>>> b=33
>>> print(a>b)
False
>>> print(a<b)
True
>>> print(a == b)
False
>>> print(a != b)
True
>>> print(a <= b)
True
13
3. Logical operators: Logical operators perform Logical AND, Logical OR
and Logical NOT operations
and Logical AND: True if both the operands are true x and y
Logical OR: True if either of the operands is
or true
x or y
>>> a = True
>>> b = False
>>> print(a and b)
False
>>> print(a or b)
True
>>> print(not a)
False 14
>>>
4. Assignment operators: Assignment operators are used to assign values
to the variables.
16
6. Membership operators: in and not in are the membership operators;
used to test whether a value or variable is in a sequence.
17
Data Types in Python
01. Integers
Integers are numbers with no decimal parts, such as -5, -4, -3, 0, 5, 7 etc. To
declare an integer in Python, simply write variableName = initial value
02. Float
Float refers to numbers that have decimal parts, such as 1.234, -0.023, 12.01. To
declare a float in Python, we write variableName = initialvalue
18
03. String
String String refers to text. To declare a string, you can either use variableName =
‘initial value’ (single quotes) or variableName = “initial value” (double quotes)
We can combine multiple substrings by using the concatenate sign (+). For instance,
“Peter” + “Lee” is equivalent to the string “PeterLee”.
19
input()
myName = input("Please enter your name: ")
myAge = input("What about your age: ")
print ("Hello World, my name is", myName, "and I am", myAge, "years old.")
Example :-
print('''Hello world.
My name is James and I am 20 Years old''')
21
Thank You
22