filmov
tv
Python Tutorial for Beginners 3 - Python Basic Syntax

Показать описание
Python Tutorial for Beginners
Tutorial 3: Python Basic Syntax
Syntax refers to the spelling and grammar of a programming language, Syntax is varies from one langauge to another but purpose of the programming concepts is almost same.
Ex:
1. Data Types - for defining type of data
2. Variables - for storing data
3. Operators - for performing Arithmetic, Comparison, and Logical etc...operations on variables and values.
4. Control Flow Statements - A program’s control flow is the order in which the program’s code executes. The control flow of a program is regulated by decision making statements, loops, and function calls.
5. Functions / Methods - for code re-usability
Etc...
Note: Purpose of Programming fundamentals like Data Types, Variables, Operators, Control Flow, Strings, Arrays etc, is almost same in every programming language, but Syntax is varies from one language to another.
We use Keywords, Identifiers, Special characters, and Data to write computer programs
Python Identifier:
A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9).
Python Keywords/Reserve Words:
In programming, a keyword is a word that is reserved by a program because the word has a special meaning. Keywords implement specific features of the language.
Every programming language has a set of keywords that cannot be used as identifiers.
All the Python keywords contain lowercase letters only.
Statement is the basic unit of code. A statement can assign a value to a variable, perform a single action, control the execution of other statements and do any number of other things.
Python Language Basic Syntax
The syntax of the Python programming language is the set of rules which defines how a Python program will be written. A Python program is divided into a number of logical lines and every logical line is terminated by the token NEWLINE. Python Program file extension is ".py"
1. Python Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
2. Python Language is Case Sensitive
Python is Case sensitive language
3. Writing Comments in Python
We use #for single comment, and '''...........''' for multi line comments in Python
4. Writing Statements, Multi-Line Statements, and Multiple Statements on a Single Line.
No formalities to write Python Statement
5. Declaration of Varaibles
Python supports Implicit declaration of variables
6. Writing Code Blocks
Python Indentation - Indentation refers to the spaces at the beginning of a code line, and Python code blocks use code indentation.
Ex:
a, b = 100, 500;
if (a b):
print ("A is Big Number")
else:
print ("B is Big Number")
for num in range(1, 6):
print(num)
7. Quotation in Python
Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long as the same type of quote starts and ends the string.
8. Functions / Methods
Some Programming features vary from one language to another
We use methods in Object Orineted Programming like Java for code reuasbility
We use Functions in C Languages for code reuasbility
Python supports both methods and functions
9. Reading Input & Display the Output
We use input function to read user input, and print function to display output.
val=input("Enter Your Name: ")
print ("Your Name is: " +val)
Tutorial 3: Python Basic Syntax
Syntax refers to the spelling and grammar of a programming language, Syntax is varies from one langauge to another but purpose of the programming concepts is almost same.
Ex:
1. Data Types - for defining type of data
2. Variables - for storing data
3. Operators - for performing Arithmetic, Comparison, and Logical etc...operations on variables and values.
4. Control Flow Statements - A program’s control flow is the order in which the program’s code executes. The control flow of a program is regulated by decision making statements, loops, and function calls.
5. Functions / Methods - for code re-usability
Etc...
Note: Purpose of Programming fundamentals like Data Types, Variables, Operators, Control Flow, Strings, Arrays etc, is almost same in every programming language, but Syntax is varies from one language to another.
We use Keywords, Identifiers, Special characters, and Data to write computer programs
Python Identifier:
A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9).
Python Keywords/Reserve Words:
In programming, a keyword is a word that is reserved by a program because the word has a special meaning. Keywords implement specific features of the language.
Every programming language has a set of keywords that cannot be used as identifiers.
All the Python keywords contain lowercase letters only.
Statement is the basic unit of code. A statement can assign a value to a variable, perform a single action, control the execution of other statements and do any number of other things.
Python Language Basic Syntax
The syntax of the Python programming language is the set of rules which defines how a Python program will be written. A Python program is divided into a number of logical lines and every logical line is terminated by the token NEWLINE. Python Program file extension is ".py"
1. Python Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
2. Python Language is Case Sensitive
Python is Case sensitive language
3. Writing Comments in Python
We use #for single comment, and '''...........''' for multi line comments in Python
4. Writing Statements, Multi-Line Statements, and Multiple Statements on a Single Line.
No formalities to write Python Statement
5. Declaration of Varaibles
Python supports Implicit declaration of variables
6. Writing Code Blocks
Python Indentation - Indentation refers to the spaces at the beginning of a code line, and Python code blocks use code indentation.
Ex:
a, b = 100, 500;
if (a b):
print ("A is Big Number")
else:
print ("B is Big Number")
for num in range(1, 6):
print(num)
7. Quotation in Python
Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long as the same type of quote starts and ends the string.
8. Functions / Methods
Some Programming features vary from one language to another
We use methods in Object Orineted Programming like Java for code reuasbility
We use Functions in C Languages for code reuasbility
Python supports both methods and functions
9. Reading Input & Display the Output
We use input function to read user input, and print function to display output.
val=input("Enter Your Name: ")
print ("Your Name is: " +val)
Комментарии