Our Frist Python Program
print("Hello World")
Hello World
print('Hello World')
Hello World
print('Inception BD')
Inception BD
print(Inception BD)
File "/tmp/[Link]", line 1
print(Inception BD)
^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
print(9)
print("9")
print(9.9)
9.9
print(True)
True
print(False)
False
print("Hello",1,2,3,4,5,6.6,True)
Hello 1 2 3 4 5 6.6 True
print("Hello",1,2,3,4,5,6.6,True, sep="-")
Hello-1-2-3-4-5-6.6-True
print("Hello",1,2,3,4,5,6.6,True, sep=",")
Hello,1,2,3,4,5,6.6,True
print("Bappy", end="-")
print("Inception")
Bappy-Inception
print("Bappy", end=" ")
print("Inception")
Bappy Inception
Data Type in Python & Comments
1. Integer
2. Float (decimal)
3. Boolean
4. String (text)
5. Complex
6. List
7. Tuple
8. Sets
9. Dictionary
# This is a single line comment, this print function prints a sentence
print("My name is Bappy")
My name is Bappy
"""
This is Multiline Comment
this print function prints a sentence
fhsdjhfksdhfkldsf
sdkhfkdjshflkdsf
sdlhfjdlkshfkdjs
"""
print("My name is Bappy")
My name is Bappy
# Integer
print(2)
print(200000000000)
200000000000
type(200000000000)
int
# Float
print(3.3)
3.3
type(3.3)
float
# Bolean
# Python is case sensative language
print(False)
False
type(False)
bool
# String
print("Bappy Inception")
Bappy Inception
type("Bappy Inception")
str
# Complex
print(5 + 7j)
(5+7j)
type(5 + 7j)
complex
# List
print([1,2,3])
[1, 2, 3]
type([1,2,3])
list
# Tuple
print((1,2,3))
(1, 2, 3)
type((1,2,3))
tuple
# Sets
print({1,2,3})
{1, 2, 3}
type({1,2,3})
set
# Dictionary
print({"Name":"Bappy", "Age":25})
{'Name': 'Bappy', 'Age': 25}
type({"Name":"Bappy", "Age":25})
dict
Variables, Keywords & Identifiers in Python
Variables
a = 2 # int
print(a)
b = 3.3 # Float
print(b)
3.3
c = True
d = 'Bappy'
print(c)
print(d)
True Bappy
Bappy
type(c)
bool
name = "Alex"
print("Welcome", name)
Welcome Alex
a = 2
b = 5
print(a+b)
# Dynamic Typing
a = 7
# Static Typing
int a = 7;
type(a)
int
a = 7
a = "bappy"
print(a)
bappy
# Dynamic Binding
a = 5
print(a)
a = "bappy"
print(a)
# Static Binding
int a = 7;
str a = "bappy";
5
bappy
a = 1
b = 2
c = 3
print(a)
print(b)
print(c)
1
2
3
a = 1
b = 2
c = 3
print(a, b, c)
1 2 3
a,b,c = 1,2,3
print(a, b, c)
1 2 3
a = 5
b = 5
c = 5
print(a, b, c)
5 5 5
a = b = c = 5
print(a, b, c)
5 5 5
Keywords
Identifiers
name = "Bappy"
print(name)
Bappy
# You can't start with any digit
1name = 'bappy'
File "/tmp/[Link]", line 3
1name = 'bappy'
^
SyntaxError: invalid decimal literal
name1 = 'bappy'
# You can't use any special chars except _
*name = "Bappy"
File "/tmp/[Link]", line 3
*name = "Bappy"
^
SyntaxError: starred assignment target must be in a list or tuple
name$ = "Bappy"
File "/tmp/[Link]", line 1
name$ = "Bappy"
^
SyntaxError: invalid syntax
_name = "Bappy"
name_ = "bappy"
_ = "bappy"
Python Input
Static - Calender, Clock
Dynamic - Youtube, Facebook
input()
{"type":"string"}
var = input()
5.6
print(var)
5.6
type(var)
str
var = float(var)
type(var)
float
var = input("Enter Your Name: ")
print(var)
Enter Your Name: bappy
bappy
Simple Calculator using input
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
result = a - b
print(result)
Enter the first number: 5
Enter the second number: 4
1
Type Conversion in Python:
1. Implicit - Internally by Python
2. Explicit - By the Programmer
# Implicit
a = 5 + 5.5
print(a)
print(type(a))
10.5
<class 'float'>
# Explicit
b = 4 + int("4")
print(b)
print(type(b))
8
<class 'int'>
num = 34
print(float(num))
34.0
num = "34"
print(float(num))
34.0
num = 3.4
print(int(num))
num = 4 + 6j
type(num)
float(num)
----------------------------------------------------------------------
-----
TypeError Traceback (most recent call
last)
/tmp/[Link] in <cell line: 0>()
3 type(num)
4
----> 5 float(num)
TypeError: float() argument must be a string or a real number, not
'complex'