During the first week of my ChiPy Mentorship program, my mentor suggested that I should brush up on some Python foundations. I learned some Python during my time at college but just enough to get through homework assignments and exams. But I never had a deep understanding of the Python language because I don’t have a deep understanding of Python’s data structures.
In order to program in any language you need to know two things, they are data types and data structures. A data type is how information is represented in a programming language. The most common data types between different languages are strings, integers, floats, and booleans. A data structure is how data is stored, accessed, modified, and organized.
Even though snakes are associated with the Python language it was named after British comedy group Monty Python. As the creator, Guido van Rossum puts it “this language is supposed to be fun and whimsical. Just like the comedy group.” And to be honest I feel like Python accomplish this feeling. I got introduced to programming with Java in high school and it sucked. I was convinced that I would never become a programmer. Ten years later I am a programmer.
I am working out my Python muscles by reading the official tutorial https://docs.python.org/3/tutorial/index.html .
Some interesting things that I’ve learned
When you type the underscore symbol _ Python prints out the last variable that was saved. But this only happens in interactive mode. If you try using this trick in your Python script you will get an error.
Python Division ( / ) returns a float and ( // ) returns a floor division. There is no special symbol for ceiling division.
To escape quotes, start new lines (\n) or any other special characters use the backslash.
If you have backlashes in your string that you don’t want to be seen as special add an r before the first quote.
Python can perform loops on sequence data types which are list, tuples, range, strings, and sets. A sequence data type is an object the stores data in a sequence. Dictionaries are considered a mapping data type and not a sequence data type since it stores data in key and value pairs.
I also found out list comprehensions and dictionary comprehensions are the same thing.
Deep Copy vs Shallow Copy
Shallow Copy — copies the reference of the original data structure
Deep Copy — copies the contents of the original data structure and it does not reference the original data structure
For a more in-depth look of copying objects check out Dan Bader’s article