What is Programming Language?
A programming language is a formal system designed to communicate instructions to a computer. It is a set of rules and syntax that allows programmers to write software, specifying how a computer should perform a certain task or set of tasks.
About Python
Python is a robust high level programming language,which is widely in use.Released in 1991, the language is developed by Guido Van Rossum.
Types of Programming language
There are three types of Programming language
Low level Programming Language i.e (Assembly)
Middle level Programming Language i.e (C)
High level Programming Language i.e (C++,Java,Python)
Software
IDLE is a python compiler to run the python code.
Link to download:-
Power and Benefits of Python
- Shell Tool
- Control Language
- Ease of use
- Freely Available
- Compatibility with platforms and languages
- Improved productivity
- Fast Runtime Structure
- Ease of learning
- Portable Implementation
- Automatic Tracking
- Automatic Memory Management
What is Print in Python
Print is considered as a statement and not a function.in python if we want to print anything in console and we will use print statement
.
Basic Structure of the Program (Hello World!)
print("Hello World")
Division with Integer
Any number specified without decimals is of type integer.This creates a problem while dividing integers which returns the decimal output so in python easy to divide integer as well as decimal numbers.
a=3/2
print(a)
Then it return 1.5 as a output
print(a)
Then it return 1.5 as a output
Unicode Support
For managing a string type, programming language implements a few diffrent ways.This enables the computer to change numbers into letters and other symbols.Python uses the American Standard Code for information interchange (ASCII) charcaters by default.
Internal working of Python
We will save the python file with .py extension.Python doesn’t convert its code into machine code, something that hardware can understand. It converts it into something called byte code. So within Python, compilation happens, but it’s just not in a machine language. It is into byte code (.pyc or .pyo) and this byte code can’t be understood by the CPU. So we need an interpreter called the Python virtual machine to execute the byte codes.
Comments in Python
Comments in Python are identified with a hash symbol, #, and extend to the end of the line.
Python Tokens and Character Sets
Python is a general-purpose, high-level programming language. It was designed with an emphasis on code readability, and its syntax allows programmers to express their concepts in fewer lines of code, and these codes are known as scripts. These scripts contain character sets, tokens, and identifiers.
Character set
A character set is a set of valid characters acceptable by a programming language in scripting.
- Alphabets: All capital (A-Z) and small (a-z) alphabets.
- Digits:All digits 0-9.
- Special Symbols:Python supports all kind of special symbols like, ” ‘ l ; : ! ~ @ # $ % ^ ` & * ( ) _ + – = { } [ ] \ .
- White Spaces: White spaces like tab space, blank space, newline, and carriage return.
- Other:All ASCII and UNICODE characters are supported by Python that constitutes the Python character set.
Tokens
A token is the smallest individual unit in a python program. All statements and instructions in a program are built with tokens. The various tokens in python are :
- Keywords:Keywords are words that have some special meaning or significance in a programming language. They can’t be used as variable names, function names, or any other random purpose. They are used for their special features. In Python we have 33 keywords some of them are: try, False, True, class, break, continue, and, as, assert, while, for, in, raise, except, or, not, if, elif, print, import, etc.
- Identifiers:Identifiers are the names given to any variable, function, class, list, methods, etc. for their identification. Python is a case-sensitive language and it has some rules and regulations to name an identifier. Here are some rules to name an identifier:-
- As stated above, Python is case-sensitive. So case matters in naming identifiers. And hence mk and MK are two different identifiers.
- Identifier starts with a capital letter (A-Z) , a small letter (a-z) or an underscore( _ ). It can’t start with any other character.
- Except for letters and underscore, digits can also be a part of identifier but can’t be the first character of it.
- Any other special characters or whitespaces are strictly prohibited in an identifier.
- An identifier can’t be a keyword.
Blocks and Indentation
Python uses indentation to highlight the blocks of code. Whitespace is used for indentation in Python. All statements with the same distance to the right belong to the same block of code. If a block has to be more deeply nested, it is simply indented further to the right.
Creating Variables
Python has no command for declaring a variable.A variable is created the moment you first assign a value to it.
Assigning Values to Variables
Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable
Taking input in Python
Developers often have a need to interact with users, either to get data or to provide some sort of result. Most programs today use a dialog box as a way of asking the user to provide some type of input. While Python provides us inbuilt functions to read the input from the keyboard.
input ():Python provides a built-in function called input which takes the input from the user. When the input function is called it stops the program and waits for the user’s input. When the user presses enter, the program resumes and returns what the user typed.
val = input("Enter your value: ")
print(val)
print(val)