Topic: Python Syntax
Day 1, we talked about how to set up Python environment on your computer. 👉( )
After today thread, you should be able to identify and debug Python syntax
Let Go 👇
#Python #twitterpython #Syntax
It is referred to a set of rules and principles that describes the structure of a language (i.e. what constitutes a correctly-formed program).
The Python syntax defines all the set of rules that are used to create sentences in Python programming
#Python3
In the same way, you will need to learn & understand the Python syntax in order to learn the Python language.
Python syntax is more like English language unlike other programming lang.
Let’s take a look at a simple Python program and you will get an idea of how programming in Python looks like.
See attached image...!
#Python #TwitterPython
1 Line Structure
2 Multiline Statements
3 Comments
4 Docstrings
5 Indentation
6 Multiple Statements in One Line
7 Quotations
8 Blank Lines
9 Identifiers
10 Variables
11 String Formatters
👿Hey, fear not its easy.....
In Python a new line means a new statement.
But sometimes, you may want to split a statement over two or more lines. It may be to aid readability. You can use following ways
>>>print("Hello\
How are day?")
>>> print("""Hi
how are you?""")
The interpreter ignores comments. Declare a comment using an octothorpe (#).
>>> #This is a comment
4 Docstrings
A docstring is a documentation string
def function(a, b):
"""Do X and return a list."""
Python supports the single quote and the double quote for string literals. But if you begin a string with a single quote, you must end it with a single quote. Same goes for double-quotes.
>>> print('We need a chaperone');
>>> print("We need a 'chaperone'");
A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9)
You cant use @, $, %
In Python, you don’t define the type of the variable. It is assumed on the basis of the value it holds.
>>> x=21
>>> print(x)
Output:
21
>>> x='Hello'
>>> print(x)
Output:
Hello
Thanks for reading But remember the best way to learn is by "Practicing"
Don't just read Practice
* Python Variables and
* Data Types