๐Ÿ“ ๐ŸŽ‰ Welcome to Variable Wonderland!#

Variables

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