Curriculum
In this lesson, you will learn about the Python basic syntax, python identifiers, variables, lines and indentation.
As we know, python is an interpreted high-level programming language, you can directly enter a code in the command line and execute it or you can create a separate file and run it in the command line.
Running a code directly on the command line is known as an interactive mode.
Whereas, executing a script file is called Script mode.
Let’s see how to execute a code in script mode.
print(“Hello World! Welcome to Developer Publish Academy”)
Keywords are reserved words that cannot be used as a variable or a value in any sort of program/script.
In python, there are a total of 31 reserved or keywords that cannot be used as a variable or value.
To find out the list of keywords, run the following code in the python shell.
import keyword Keyword.kwlist
Output:
[gamipress_button type=”submit” value=”RUN CODE SNIPPET” onclick=”window.open(‘https://coderseditor.com/?id=1163′,’_blank’)”]
Generally, an identifier is a variable, a function, a class, a module. Whenever you provide a name to a certain object in python it is termed as an identifier.
Rules for a valid identifier
It should start with a letter(A-Z, a-z both apply).
It can also start with an underscore(_) followed by alphanumeric characters.
Types of Identifiers in Python
Comments are non-executable sentences in python. It is used to provide a detailed meaning of your code. You can include a comment into your code to make it more understandable to yourself/other programmers.
To write a comment in python:
Example:
Print(“Developer Publish”) #this is a simple code for printing Developer Publish
Unlike C, python does not have braces to determine the block of code. So to tackle this, python follows a strict indentation policy.
Indentation is the white space before certain lines of code in python. The number of spaces may vary depending on the line of code.
For instance,
The ‘for’ statement will have one space before it and the ‘if’ statement will have two spaces.
Indentation increases the readability of the code which helps python to execute or run the code properly. Python throws an indentation error if the indentation provided in the code is incorrect
Follow these simple rules to avoid Indentation errors: