Python Basics Notes

Piyush KabraPiyush Kabra
2 min read

CPU Operations are also known as Computing

x = 5 ( 5 is Data )
x -> Variable / Placeholder / Reference

In a Real Scenario, The Kernel is the one that controls the whole device, not the operating System.

y = 10
print (y) → 10
type (y) → int
id (y) → 1403948392940284

in y = 10, there are two questions ->
1. Where is data stored & 2. What is a data type?
in “id (y)” in “type (y)”

#Python Works on #Type_inference which is the process of automatically determining the data type of an expression within a programming language.

y = 10 ( int ) { No Error in this }
y = 29.3 ( float )

If I try to write y = piyush in Python it will show an error because Python will think “y” & “piyush” both are strings or any function, so it will not assign.

That’s why we use y = “piyush”, and “ “ for telling it is a string.
type(y) -> str

— — — — — — — — — — — — — — — — — — — -
#Polymorphism in Python:-

a = 5 , b = 10
i = “piyush”, j = “kabra”

a + b = 15 ( Addition Here )
a + i = error
i + j = ‘piyushkabra’ ( Concatenation Here )

so the “+” operator is doing addition & concatenation, so it is an example of polymorphism in Python. ( One operator Multiple form )

— — — — — — — — — — — — — — — — — — — -
#String_Interpolation

n = “piyush” → hardcoded
print (“ my name is piyush “) → hardcoded

To tell n is a variable we use {n} Curly braces:-
print (“ my name is {n} “) — -> o/p is — -> my name is {n}
Things inside “ “ will print it as it is,

So, to bring the value to n, we use #formatString or #f_strings
→ print (f” my name is {n}”)
o/p → My name is piyush.

#Older_way :-
print(“my name is {}”.format(n))
o/p → My name is piyush

fname = “piyush”
lname = “kabra”

print(f”my name is {fname} {lname}”)
print(f”my name is {} {}”.format(fname, lname) )
0 1 → by Default
1 0 — -> kabra piyush
1 1 — -> kabra kabra

0
Subscribe to my newsletter

Read articles from Piyush Kabra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Piyush Kabra
Piyush Kabra