Simple Print Code using Python
Here is a simple code to show you how Python is simple and easy to learn for a person who has no programming knowledge. The user can execute Python syntax by writing directly in the Command Line.
Basic Python Syntax
Code
print("Hello, Python!")
PythonHello, Python! |
Indentation
Python indentation shows that when a block of code begins and ends. In Python indentation is very important its not just a simple spacing for the readability of code it’s a predefined set of rules for spacing of code If you write a code without indentation it will generate an error. Other programming languages use brackets or keywords instead. Let’s use an example to understand indentation.
print("""
{
"Hello, Python"
}
""")
PythonOutput: { “Hello, Python” } |
As we can see in the above example print is indented four spaces.
Comments in Python:
Comments are very useful lines to explain any code line to others. It is a good practice for a developer to add comments to the code. There the two types of comments single-line comments and multiple-line comments.
Single-line comments can be used by writing # as you can see in the following example:
#This is a single-line comment
PythonMultiple-line comments can be written by using “””” ””” triple quotes as you can see in the following example:
"""
This is a multiline comment.
It can span multiple lines without causing any syntax errors.
You can use either single quotes or double quotes for multiline comments.
"""
PythonComment lines will be ignored by the Python interpreter.
Example:
Code
# Print Hello Python
print("Hello Python")
PythonOutput: Hello Python |
Reserved Words:
The reserve has a specific use you can not use the theme as a variable name, object name, or any constant or identifier name. Every language has its own reserved words also known as keywords. The following list shows Python reserved.
Python Keywords
And | exec | not |
assert | finally | or |
break | for | pass |
class | from | |
continue | global | raise |
def | if | return |
del | import | try |
elif | in | while |
else | is | with |
except | lambda | yield |
Data Types in Python
In every programming language, there will be nothing done without data and every piece of data has its type there are different types of data. In Python, we have some built-in data types for different types of data as:
Built-in Data Types | Types of Data |
str | Text Type |
int, float, complex | Numeric Type |
list, tuple, range | Sequence Type |
dict | Mapping Type |
Set, frozenset | Set Type |
bool | Boolean Type |
Bytes, bytearray, memoryview | Binary Type |
We can check the type of data by using the type () function:
Example:
Print the data type of the variable x:
Code
X = 3
print(type(X))
PythonOutput:<class 'int'> |
Escape Sequence
Escape sequences are control characters used to move the cursor and print such as ‘, “, \, etc.
Escape Sequence | Meaning |
\a | Bell |
\b | Backspace |
\f | Form feed |
\n | Newline |
\r | Carriage Return |
\t | Horizontal Tab |
\v | Vertical Tab |
\newline | Backslash and Newline ignored |
\\ | Backslash |
\’ | Single Quote |
\” | Double Quote |
Author: TCF Editorial
Copyright The Cloudflare.