0% found this document useful (0 votes)
9 views8 pages

001-b Code

The document is a tutorial on basic Python programming concepts, including print statements, variables, and data types. It demonstrates various print functionalities, variable assignments, and memory management through examples. Additionally, it covers the use of the Decimal module for precise arithmetic operations and lists Python's reserved keywords.

Uploaded by

giretab697
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

001-b Code

The document is a tutorial on basic Python programming concepts, including print statements, variables, and data types. It demonstrates various print functionalities, variable assignments, and memory management through examples. Additionally, it covers the use of the Decimal module for precise arithmetic operations and lists Python's reserved keywords.

Uploaded by

giretab697
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

colab-class-1

November 10, 2024

0.0.1 Print Statement


[ ]: print("Hello World")
print("Venky")

Hello World
Venky
Hello World Venky
[ ]: # use case of end

print("Hello World", end="\n")


print("Venky")

Hello World
Venky

[ ]: print("Hello World\n")
print("Venky")

Hello World

Venky

[ ]: # use case of sep

print("Hello", "Venky", "Gate", sep=" ")

Hello Venky Gate

[ ]: #print("Hello", "Venky", "Gate", sep="")


#print("Hello", "Venky", "Gate", sep="---")
print("Hello", "Venky", "Gate", sep="\n")

Hello
Venky
Gate

1
[ ]: print("Welcome to RBR Course", "This is Venky", sep="++", end="***")
print("Checkout to this course", end="\n\n")
print("Python programming")

Welcome to RBR Course++This is Venky***Checkout to this course

Python programming

0.1 Variables
[ ]: 2+3

[ ]: 5

[ ]: 4+5

[ ]: 9

[ ]: # you are given a salary and u need to calculate the savings

v = 100000

expenditure = 10000 + 12000 + 30000

[ ]: v - 10000

[ ]: 90000

[ ]: v+12000

[ ]: 112000

[ ]: value = 100

id(value)

[ ]: 137443867102544

[ ]: type(value)

[ ]: int

[ ]: a = 100

id(a)

[ ]: 137443867102544

2
[ ]: a = 100
b = 100
print(id(a))
print(id(b))
print("After Changing")
b = b+20
print("b:", b)
print(id(a))
print(id(b))
a = 120
print(id(a))

137443867102544
137443867102544
After Changing
b: 120
137443867102544
137443867103184
137443867103184

[ ]: del a

[ ]: print(b)
print(id(b))

120
137443867103184

[ ]: f = 12.5
print(f)
print(type(f))
print(id(f))

12.5
<class 'float'>
137442585477424

[ ]: # valid variable names


name = "venky"
age = 26
_salary = 12000

[ ]: n8ame = "venky"

[ ]: name = "Venky"
Name = "RBR"
NAME = "Jay Bansal"

3
NAME_2 = "Venky"
print(name)
print(id(name))
print(Name)
print(id(Name))
print(NAME)
print(id(NAME))
print(id(NAME_2))

Venky
137442586806832
RBR
137442586812528
Jay Bansal
137442584224304
137442586806832

[ ]: name = "Venky"
name_2 = "VENKY"

print(id(name))
print(id(name_2))

137442586806832
137442585736176

[ ]: name = "Venky"

name.removeprefix("Ven")

[ ]: 'ky'

[ ]: k = 4/2
i = 2.0
i == k

[ ]: True

[ ]: id(i)

[ ]: 136008100513008

[ ]: id(k)

[ ]: 136008100513552

4
[ ]: k

[ ]: 2.0

[ ]: i

[ ]: 2.0

[ ]: k = 4//2
i = 2
id(k)

[ ]: 136009076605200

[ ]: id(i)

[ ]: 136009076605200

[ ]: k = 12345
m = 12345

id(k)

[ ]: 136008100511920

[ ]: id(12)

[ ]: 136009076605520

[ ]: 136009076605520-136009076605456

[ ]: 64

[ ]: id(10)

[ ]: 136009076605456

[ ]: from decimal import Decimal


Decimal(0.1+0.2)

[ ]: Decimal('0.3000000000000000444089209850062616169452667236328125')

[ ]: vn = Decimal(0.1)+Decimal(0.2)
vn

[ ]: Decimal('0.3000000000000000166533453694')

5
[ ]: v = 0.5
n = 0.5

id(v)

[ ]: 136008100519824

[ ]: id(n)

[ ]: 136008100521584

[ ]: v = n
id(v)

[ ]: 136008100521584

[ ]: id(n)

[ ]: 136008100521584

[ ]: v = 1
n = 1
id(v)

[ ]: 136009076605168

[ ]: import decimal

a = decimal.Decimal('1.1')
b = decimal.Decimal('2.2')

c = a+b
print(c)

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-102-2bd55a2c550f> in <cell line: 7>()
5
6 c = a+b
----> 7 print(c)

TypeError: 'int' object is not callable

[ ]: id(n)

[ ]: 136009076605168

6
[ ]: id(n)

[ ]: 136008100521936

[ ]: Decimal(0.5)

[ ]: Decimal('0.5')

[ ]: import keyword
keyword.kwlist

[ ]: ['False',
'None',
'True',
'and',
'as',
'assert',
'async',
'await',
'break',
'class',
'continue',
'def',
'del',
'elif',
'else',
'except',
'finally',
'for',
'from',
'global',
'if',
'import',
'in',
'is',
'lambda',
'nonlocal',
'not',
'or',
'pass',
'raise',
'return',
'try',
'while',
'with',
'yield']

7
[ ]: a = None
b = None

a==b

[ ]: True

[ ]: print(type(a))
print(type(b))

<class 'NoneType'>
<class 'NoneType'>
<class 'NoneType'>
<class 'NoneType'>

[ ]: 0.1

[ ]: 0.1

You might also like