phyton have a syntax?
YES
Why Python?
Execute Python Syntax
As we learned in the previous page, Python syntax can be executed by writing directly in the Command Line:
>>> print("Hello, World!")
Hello, World!
Python Comments
Comments can be used to explain Python code.
Comments can be used to make the code more readable.
Comments can be used to prevent execution when testing code.
Variables
Variables are containers for storing data values.
yes
Python Syntax compared to other programming languages
Python Indentation
Indentation refers to the spaces at the beginning of a code line.
Creating a Comment
Comments starts with a #, and Python will ignore them:
Creating Variables
Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.
By who is created phyton
Guido van Rossum
It is used for:
Comments
Python has commenting capability for the purpose of in-code documentation.
Multi Line Comments
Python does not really have a syntax for multi line comments.
To add a multiline comment you could insert a # for each line:
Casting
If you want to specify the data type of a variable, this can be done with casting.
released in
1991
What can Python do?
Example
#This is a comment.
print("Hello, World!")
Try it Yourself »
A comment does not have to be text that explains the code, it can also be used to prevent Python from executing code:
Example
#print("Hello, World!")
print("Cheers, Mate!")
Get the Type
You can get the data type of a variable with the type() function.
What can Python do?
Good to know
Example
Syntax Error:
if 5 > 2:
print("Five is greater than two!")
print("Five is greater than two!")
Or, not quite as intended, you can use a multiline string.
Since Python will ignore string literals that are not assigned to a variable, you can add a multiline string (triple quotes) in your code, and place your comment inside it:
This is a comment
written in
more than just one line
"""
print("Hello, World!")
Try it Yourself »
Single or Double Quotes?
String variables can be declared either by using single or double quotes: