18CSGB0 PROGRAMMING USING PYTHON
Dr.M.Nirmala Devi,
Assistant Professor,
Department of Computer Science and Engineering,
Thiagarajar College of Engineering,
Madurai, Tamil Nadu
18-Aug-20 Dr.M.Nirmala Devi,AP,CSE,TCE 1
print("Hello, World!")
variable
x=5
y = "John"
print(x)
print(y)
18-Aug-20 Dr.M.Nirmala Devi,AP,CSE,TCE 2
Many/Multiple Values to Multiple Variables
5
John
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
18-Aug-20 Dr.M.Nirmala Devi,AP,CSE,TCE 3
One Value to Multiple Variables
Orange
Banana
Cherry
x = y = z = "Orange"
print(x)
print(y)
print(z)
18-Aug-20 Dr.M.Nirmala Devi,AP,CSE,TCE 4
OUTPUT= Combine any two string
Orange
Orange
Orange
x = "Python is "
y = "awesome"
z=x+y
print(z)
Python is awesome
18-Aug-20 Dr.M.Nirmala Devi,AP,CSE,TCE 5
Casting –Type Casting
• x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
• Single or Double Quotes?
•x=5
y = "John" • x = "John"
print(type(x)) # is the same as
print(type(y)) x = 'John'
Case-Sensitive
• Variable names are case-sensitive.
• Example
• This will create two variables:
•a=4
• A = "Sally“
• A=5
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)
LEGAL AND ILLEGAL VARIABLE NAMES
• Legal variable names: • Illegal variable names:
• 2myvar = "John"
• myvar = "John" my-var = "John"
my_var = "John" my var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John“
Multi Words Variable Names
• Variable names with more than • Pascal Case
one word can be difficult to read. • Each word starts with a capital
• There are several techniques you letter:
can use to make them more • MyVariableName = "John"
readable:
• Snake Case
• Camel Case
• Each word is separated by an
• Each word, except the first, starts underscore character:
with a capital letter:
• my_variable_name = "John"
• myVariableName = "John"
Know the Terms
Compilation and Interpretation
Python?- PVM
Byte code-> .Class -Frozen binary executables
Platform Independent
Script and Module [Package]
Which is fast-Python and C
Python OOP or General Purpose language
C Compilation
#include <stdio.h>
int main()
{
printf("Hello ");
return 0;
}
#include <stdio.h>
int main()
{
printf("Hello ");
return 0;
}
• In case- Write –logic function- Time complexity low
• Python- Built-in Function[For all logics]
• Searching the Fn as well retrieving corresponding logic[Block of code]-
Time consuming
• C is faster
Python Interpreter