On the first day of my #100DaysOfCode journey, I dove into Angela Yu's exceptional Udemy course, "100 Days of Code: The Complete Python Pro Bootcamp for 2023." I tackled the first three sections, which covered topics such as variables, data types, string manipulation, control flow, and logical operators.
As with learning any programming language, Python also involves variables, data types, and the manipulation of values based on the data type held by the variable. To enrich my understanding, I turned to Google for additional details and sample code.
I discovered an interesting Python feature that allows you to indicate a variable's data type during assignment:
x = 23
x: int = 23
y = 11.5
y: float = 11.5
These type hints improve code readability however, they're completely optional and don't prevent you from assigning a different value later.
While exploring string formatting, I learned that Python 3.6 introduced f-strings, a more readable and faster formatting method compared to the older .format() and % formatting techniques. Here are a couple of examples demonstrating control over the formatted output:
`stars = 5
msg = "python is awesome."
print(f"{msg.upper()} I give it {stars*2} stars.")
amt = 2_534.123456
print(f'Floating point with 2 decimal: {amt:0.2f}')
I also experimented with common string methods such as count(), removeprefix(),
index(), split(), replace(), lower(), upper(), startswith(), endswith(), and strip():
txt = " Hello John, welcome to the world Python. "
print(f"txt: {txt}")
print(f'count(): {txt.count("o")}')
print(f'index(): {txt.index("welcome")}')
print(f"split(): {txt.split()}")
print(f'replace(): {txt.replace("John", "Mark")}')
print(f"strip(): No more extra spaces before {txt.strip()} or after")
txt = "Hello John, welcome to the world Python."
print(f"removeprefix(): {txt.removeprefix('Hello')}")`
Lastly, I covered the 'if' statement, which, as expected, controls the flow of an application based on logical conditions. I'm still adapting to Python's indentation requirements for statements and the colons at the end of 'if', 'elif', and 'else'. I also find myself forgetting to omit the semicolon at the end of a line – a habit carried over from the Java and JavaScript world.
But I'm sure I'll get used to it soon!
Top comments (0)