What is Python Syntax?
The Python syntax defines all the set of rules that are accustomed find yourself sentences in Python programming.
For example – we've to be told linguistics to be told land language. At intervals an identical approach, you'll need to learn and understand the Python syntax thus on be told the Python language.
Example of Python Syntax
Python may well be a classy language thanks to its elegant syntax structure.
Example – how to print hello somay in python
Print(“ Hello somay”)
Types of Syntax Structures in Python
1. Python Multiline Statements
This one can be a major Python syntax. We have a bent to tend to saw that Python does not mandate semicolons.
A the new line suggests that an innovative statement. But sometimes, you'll have to be compelled to separate associate degree announcements over a mix of or several lines.
It may be to help readability. You’ll be able to do this at intervals consecutive ways that} in at intervals which.
Ex --- use backslash
Print(“ hello somay\
Welcome to Teknologiyamechta”)
Comments
Python Syntax ‘Comments’ amendment you to store tags at the proper places at intervals the code. You’ll be able to use them to clarify difficult sections of code.
Ex --- # This is a teknologiyamechta blog
The interpreter ignores comments. Declare a comment observe Associate in Nursing Hash (#).
Python Indentation
Since Python doesn’t use kinky braces to delimit blocks of code, this Python Syntax is important
Ex ---- for i in range(3,10):
Print(i)
You can indent code below a perform, loop, or class.
Python Multiple Statements in One Line
You can else extract quite one statement on one line. Try this by separating them with punctuation.
Ex --- a= “somay”; print(a);
But you’d alone have to be compelled to try to do and do this if it supplements readability.
Python Quotations
Python supports the sole real quote and then the double quote for string literals. But if you begin a string with one quote, you'd want to finish it with one quote.
Ex – print(‘welcome to tekhnologiyamechta blog’)
The same goes for double-quotes.
The following string is delimited by single quotes.
Python Blank Lines
If you allow a line with simply whitespace, the interpreter will ignore it.
Python Identifiers
An image may well be a reputation of a program [*fr1], and it's user-defined. This Python Syntax unambiguously identifies the [*fr1].
There are some rules to follow whereas choosing an Associate in nursing identifier:
Keyword of python
and |
def |
False |
import |
not |
True |
as |
del |
finally |
in |
or |
try |
assert |
elif |
for |
is |
pass |
while |
break |
else |
from |
lambda |
|
with |
class |
except |
global |
None |
raise |
yield |
continue |
exec |
if |
|
|
An image might alone begin with A-Z, a-z, or Associate in Nursing underscore (_).
This may even be followed by letters, digits, and underscores- zero or several.
Python is case-sensitive. Name and name are a mix of fully altogether completely totally different identifiers.
A reserved keyword won't be used as Associate in nursing image. Succeeding may well be an inventory of keywords.
Python Variables
In Python, you don’t define the sort of the variable. It’s assumed on the thought of the value it holds.
Ex --- a=13
b= 17
c= a+b
print(c)
output – 30
a, b, c is the variable and store some value in the given example
Summary
In this Python Syntax tutorial, we have a bent to tend to learn regarding the essential Python syntax.
We learned regarding its line structure, multiline statements, comments and indentation, and quotations.
We else learned regarding blank lines, identifiers, variables, multiple statements in one line.
#somaymangla #somaymangla #somaymangla
#somaymangla
#somaymangla
Author
No comments:
Post a Comment