Python vs. Java - Braces | COMP70050: Introduction to Machine Learning | Department of Computing | Imperial College London home article Introduction to Machine Learning COMP70050 Autumn Term 2021/2022 Introduction to Python for Java programmers The Zen of Python Example Python program Python vs. Java - Main method Python vs. Java - Variable declaration Python vs. Java - Semicolons Python vs. Java - Braces Python vs. Java - Comments Running Python Running Python as a script Running Python interactively Basic built-in data types Everything is an object Reserved words Variables - Java 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. Java - Braces Curly braces are not used in Python for marking blocks. Instead, Python uses a combination of colon (:) and indentations to indicate a block. Therefore, unlike in Java, indentation is compulsory in Python. But then again, you should be indenting your code anyway whether it is Python or Java! You can use spaces or tabs to indent your code (four spaces is officially recommended). You must however NOT mix spaces and tabs in your code. This will result in a syntax error. Pick one and be consistent. << Previous Next >> Page designed by Josiah Wang Department of Computing | Imperial College London