๐ ๐ Welcome to Variable Wonderland!#
Brace yourselves! Weโre diving into Pythonโs world of variables and objects. ๐
๐งช What are Variables?#
Think of variables as the digital Post-it Notes of programming. Stick whatever you want on themโnumbers, text, or your hopes and dreams (just kidding, maybe).
x = 5
y = 'Drexel'
print(f'Behold x: {x} and y: {y}')
Behold x: 5 and y: Drexel
๐คฏ Guess What? No Declarations!#
Unlike some languages that nag you to declare everything (cough C++), Python is cool. Assign a value, and voilร ! The variable exists.
z = 42.0
print(type(z)) # Python knows it's a float!
<class 'float'>
๐ญ Strings Are Drama Queens#
Wrap them in single ('
) or double ("
) quotes. Python doesnโt judge, but keep it consistent!
name1 = 'Engineer'
name2 = "Extraordinaire"
print(f'Hello, {name1} {name2}!')
Hello, Engineer Extraordinaire!
๐ Python is Case-Sensitive#
x
and X
are NOT the same. Engineers, donโt lose your variables to uppercase confusion!
x = 5
X = 10
print(f'Lowercase x: {x}, Uppercase X: {X}')
Lowercase x: 5, Uppercase X: 10
๐บ Dance of Variable Names#
Variable names must waltz to these rules:
Start with a letter or underscore.
Canโt start with a number (Python hates leading digits).
Alpha-numeric and underscores onlyโno emojis! ๐ข
And yes, they are case-sensitive (again, watch out!).
๐คนโโ๏ธ Juggling Variables#
Python loves efficiency. Assign multiple variables in one go:
a, b, c = 1, 'fun', 3.14
print(f'Values: a={a}, b={b}, c={c}')
Values: a=1, b=fun, c=3.14
๐ Objects Are Everything#
Python treats variables like celebritiesโeverything is an object with special powers (methods).
s = 'Engineering Rules!'
print(s.upper()) # SHOUT IT!
ENGINEERING RULES!
f = 100.0
print(f.is_integer()) # Is this an integer, really?
True