0% found this document useful (0 votes)
36 views

Python Kuppiya 01 - E19

The document discusses various programming concepts in Python including data types, variables, operators, input/output functions, and comments. It provides examples and explanations of integers, floats, strings, arithmetic operators, relational operators, logical operators, assignment operators, and input functions in Python. The document is intended to teach Python programming basics and fundamentals to beginners.

Uploaded by

Amandi Perera
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Python Kuppiya 01 - E19

The document discusses various programming concepts in Python including data types, variables, operators, input/output functions, and comments. It provides examples and explanations of integers, floats, strings, arithmetic operators, relational operators, logical operators, assignment operators, and input functions in Python. The document is intended to teach Python programming basics and fundamentals to beginners.

Uploaded by

Amandi Perera
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Kuppiya - E19

1
What is a programming Language

Program
Computer
Programmer
Programming Language

2
Why we learn python?

 Beginners friendly language


 Easy to learn
 Good for beginners to start
 Python can be used for a large variety of tasks, such
as for
❖ Desktop applications
❖ Database applications
❖ Network programming
❖ Game programming and even mobile development
3
Installing the Python Interpreter

 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.

userAge, userName = 30, ‘Peter’

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.

OPERATOR DESCRIPTION SYNTAX

+ Addition: adds two operands x+y

- Subtraction: subtracts two operands x-y

* Multiplication: multiplies two operands x*y


/ Division (float): divides the first operand by the second x/y
// Division (floor): divides the first operand by the second x // y
Modulus: returns the remainder when first operand is divided by
% the second x%y
** Power : Returns first raised to power second x ** y 10
Example :-
>>> a=9
>>> b=4
>>> add=a+b
>>> print(add)
13
>>> sub=a-b
>>> print(sub)
5
>>> div1=a/b
>>> print(div1)
2.25
>>> div2=a//b
>>> print(div2)
2
>>> mod = a%b
>>> print(mod)
1
>>> power = a**b
11
>>> print(power)
6561
2. Relational Operators: Relational operators compares the values. It
either returns True or False according to the condition

OPERATOR DESCRIPTION SYNTAX


Greater than: True if left operand is greater than the
> right
x>y

< Less than: True if left operand is less than the right x<y

== Equal to: True if both operands are equal x == y

!= Not equal to - True if operands are not equal x != y

Greater than or equal to: True if left operand is


greater than or equal to the right
>= x >= y
Less than or equal to: True if left operand is less than
or equal to the right
<= x <= y
12
Example : -

>>> 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

OPERATOR DESCRIPTION SYNTAX

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

not Logical NOT: True if operand is false not x

>>> 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.

OPERATOR DESCRIPTION SYNTAX


Assign value of right side of expression to left side
= operand x=y+z
Add AND: Add right side operand with left side
+= operand and then assign to left operand a+=b a=a+b
Subtract AND: Subtract right operand from left
-= operand and then assign to left operand a-=b a=a-b
Multiply AND: Multiply right operand with left
*= operand and then assign to left operand a*=b a=a*b
Divide AND: Divide left operand with right
/= operand and then assign to left operand a/=b a=a/b
Modulus AND: Takes modulus using left and right
%= operands and assign result to left operand a%=b a=a%b
Divide(floor) AND: Divide left operand with right
operand and then assign the value(floor) to left
//= operand a//=b a=a//b
Exponent AND: Calculate exponent(raise power)
value using operands and assign value to left
**= operand a**=b a=a**b 15
5. Identity operators: is and is not are the identity operators both are
used to check if two values are located on the same part of the memory. Two
variables that are equal does not imply that they are identical.

OPERATOR DESCRIPTION SYNTAX


is True if the operands are identical x is y

is not True if the operands are not identical x is not y

Now run the program. You should get this output:

16
6. Membership operators: in and not in are the membership operators;
used to test whether a value or variable is in a sequence.

OPERATOR DESCRIPTION SYNTAX

in True if value is found in the sequence x in y


True if value is not found in the
not in sequence
x not in y

Now run the program. You should get this output:

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

Example: userAge = 20, mobileNumber = 12398724

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

Example: userHeight = 1.82, userWeight = 67.2

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)

Example: userName = ‘Peter’, userSpouseName = “Janet”, userAge = ‘30’

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.")

When input an integer


Num1=int(input("Enter a Number:"))
print(Num)

When input a float


Num2=float(input("Enter a Number:"))
print(Num)
20
Triple Quotes
If you need to display a long message, you can use the triple-quote symbol (‘’’ or
“””) to span your message over multiple lines. For instance,

Example :-

print('''Hello world.
My name is James and I am 20 Years old''')

21
Thank You

22

You might also like