Lab Tutorial
Python for C++ Programmers
- Introduction to Python for C++ programmers
- The Zen of Python
- Example Python program
- Python vs. C++ - Main function
- Python vs. C++ - Variable declaration
- Python vs. C++ - Semicolons
- Python vs. C++ - Braces
- Python vs. C++ - Comments
- Running Python
- Running Python as a script
- Running Python interactively
- Basic built-in data types
- Everything is an object
- Reserved words
- Variables - C++ vs. Python
- Python Variables
- Objects in Python
- Operators
- Assignment operator
- Lists
- Accessing Lists
- Modifying Lists
- Tuples
- Strings are sequences
- Formatting strings
- Sets
- Dictionaries
- Grouping data with dict and tuple
- Control flow
- Loops
- Useful objects for loops
- List comprehensions
- Functions
- Function arguments
- Built-in functions
- Object-Oriented Programming in Python
- Constructor
- Attributes
- Methods
- Magic/Dunder methods
- Inheritance
- Encapsulation
- Encapsulation the Pythonic way
- What about protected?
- Python modules
- Custom modules
- What's in a __name__?
- Handling text files
- Reading CSV files
- Writing to CSV files
- Handling JSON files
- Pickle
- That's a wrap!
Python vs. C++ - Main function
Let’s put the C++ and Python codes side-by-side to compare them (You can click on the image for a larger version)
Firstly, the main function is not needed in Python. When you run a Python script, everything that’s not defined in a function or class will be executed.