In this article, you will learn about Python’s basic Syntax. It is very simple just like the common English language. There is no need to end a Python statement by using the semicolon “;”.
We can use the command line to run Python code.
Python Print Statement
Usually, when we start learning any new programming language we begin with learning to print the “Hello world” on the screen.
Variables are used to store any value. In other programming languages like C, C++, and Java a variable is specified by a data type. But in Python Variables are automatically assigned by a data type based on the value that you are given
Comments are the pace of code that is never executed. Python comments begin with the “#” symbol. All the codes after that are ignored.
# This is a single line comment print("Code after comment")
Code after comment
Python supports multiline comments that are discussed in the Python Comments section.
Python User Input
Sometimes users want to interact with the program by entering any value. The bellow function is used in Python to take any value from the user.
Input (Prompt) Prompt is the display message on the screen while taking input from the user. It can be anything like “Enter a number” etc.
a= input("Enter a number") print(a)
For more information about input and output in Python, you are referred to the Python input/output tutorial.
Python Print Multiple Statements in a Single Line
Below is the code to print multiple statements in a single line.
a=10; b=20; c=20; print (a,b,c)
10 20 20
Python multiple lines
In Python backslash “\” is known as a continuation character that is used to indicate the continuation of a line. It is used when we break down the long string into multiple lines.
message ="You are reading this article on:" \ "www.logictoprogram.com" print(message)
You are reading this article on:www.logictoprogram.com
Indention or indent basically is the spaces within the code. In other programming languages, you use braces to represent a single block of code. But in Python, we use left indent to specify a block.
if 20 > 10: print("20 is greater then 10.")
20 is greater then 10.