BASICS OF PYTHON
Program :- A program is a set of instructions that perform a specific tasks.
Python :-
- It is created by Guido Van Rossum in the late 1980's at National research Institute for Mathematics and Computer Science in the Netherlands.
- Easy to learn and use.
- It is very powerful and expressive high level language.
- It is an open source, cross-platform, dynamic and interpreted high level language.
- It is derived from many other languages such as ABC, Modula-3, C, C++, Algol-68, SmallTalk, and unix shell.
- It's interpreter and extensive standard library available at "http://www.python.org/"
Features of Python :-
- It is easy to use and learn.
- It has a broad library.
- It is a free and open source.
- It is portable and interpreted.
- It is based on object-oriented concepts.
- It is extensible.
- It is dynamically typed.
- Interactive Mode.
- Script mode.
- Interactive mode is a command line shell which gives immediate results for each statement.
- Interactive mode makes it easy to test code snippets before incorporating them into a larger program.
- The ">>>" is called Python Prompt which indicates that we are in interactive mode i.e. it is ready to take input from the user.
- We use the script mode to write a set of statements in Python.
- In this mode, a set of statements is stored in a file with .py extension.
IDLE :- It is a graphical "Integrated Development Environment" for Python. It contains a Python shell program that lets us type instruction into the compiler.
Different IDE where python code can be executed
Different IDE where python code can be executed
- Jupyter
- Anaconda
- Spyder
- Gitbash with VSode
- Pycharm
- PyScripter IDE
- Jython (Java)
- IronPython (.NET)
Python as Interpreted Language :-
- Python is interpreted language , i.e. it is processed at runtime by the interpreter and it need not to compile the program before executing it.
- The interpreter checks through the code for errors and interprets the instructions into machine readable "bytecode"
- This is similar to PERL and PHP.
- Python code is translated into intermediate code called byte code, which has to be executed by a virtual machine known as Python Virtual Machine (PVM).
- A bytecode is a byte-long instruction that python interpreter generates and executes.
- Execution of a python program means execution of the byte code on the Python Virtual Machine (PVM).
Applications of Python
- Web development
- Machine Learning
- Deep learning
- Rapid Prototyping
- Scripting
- Game development
- System administration
- GUI Programming
Python Character Set :- Character sets are the building blocks of any programming language. In Python basic program elements are identifier or variable, array, etc as given below.
Letters :- Uppercase Letters (A-Z)
Lowercase Letters (a-z)
Digits :- 0.........9
Special Characters :- / * + \ " < > # ( ) = | { % - ; } [] / ^ - :' ? & _ '.
(blank)
White spaces :- Blank spaces, Tab, carriage return, newline, form feed
Other Characters :- It can process all ASCII and UNICODE character as part of data or literals.
Letters :- Uppercase Letters (A-Z)
Lowercase Letters (a-z)
Digits :- 0.........9
Special Characters :- / * + \ " < > # ( ) = | { % - ; } [] / ^ - :' ? & _ '.
(blank)
White spaces :- Blank spaces, Tab, carriage return, newline, form feed
Other Characters :- It can process all ASCII and UNICODE character as part of data or literals.
Token :- A token is the smallest unit of the program. The various tokens of python are shown below :
- It is also known as Lexical unit.
- In a passage of text, individual words and punctuation marks are called token or lexical units
- Python has following tokens: -
- Keywords
- Identifiers
- Literals
- Operators
- Punctuation.
Keywords in Python :-
- Python keywords are special reserved words.
- Convey a special meaning to the compiler / interpreter.
- Each keyword has a special meaning and a specific operation.
- It is not used as variable, method or class names.
- There are 33 keywords in Python and are case sensitive.
- Example : True, False, None, and, as , asset, def, class etc.
Literals in Python :- In Python literals mean data items that have a constant value. Following are the types of literals :-
- String Literals
- Numeric Literals
- Boolean Literals
- Special Literals
** These are the data which are stored in a variable.
String Literals :- It is a sequence of characters surrounded by quotes ( single, double or triple)
Example : - >>> name1 = "John"
>>> name2 = 'James'
Numeric Literals :-
String Literals :- It is a sequence of characters surrounded by quotes ( single, double or triple)
Example : - >>> name1 = "John"
>>> name2 = 'James'
Numeric Literals :-
Int | long | float | complex |
---|---|---|---|
+ve & -ve numbers (integers) with no fractional part Example :- 100, 24 | unlimited integer size followed by upper or lower case L Example :- 2345446L | Real numbers with both integers and fractional part Example:- 213.32 | In the form of a + bj. 'a' form the real part & 'bj' forms the imaginary parts Example :- 3+4j |
Boolean Literals :- It can have two values "True" or "False" , where condition of two value is required.
Special Literals :- Python has one special Literal : None, It is used to specify that field which is not created.
Example:- >>> val2 = None ("There is nothing here")
Identifier :- Identifiers are names given to program elements such as variables, arrays and functions. Basically, identifiers are the sequences of alphabet or digits.
Variable :-
Identifier :- Identifiers are names given to program elements such as variables, arrays and functions. Basically, identifiers are the sequences of alphabet or digits.
Variable :-
- A variable is declared to hold some spaces in the memory.
- The data stored in a variable can then be modified, stored or displayed whenever needed.
- Example :- sum = 0 ("here sum is variable with a default value of 0 and when a user enters data, the variable changes to the data entered by users.
Escape Sequence :-
- It is a special character followed by a backslash (\).
- This makes the normal character to be interpreted with a new meaning.
- Example :- 'n' becomes new line character after adding (\), i.e. '\n'.
- \\ - Backslash (\)
- \' - single quote (')
- \r - carriage return
- \t - Horizontal tab
- \000 - character set with octal value
Comment :-
- A line of text which starts with a hash (#) symbol is known as comment in Python
- It will be skipped by the interpreter during the program execution.
- A comment can be written as a new line or with the statement or expression line.
- Example : - >>> # This is a new line comment at interactive mode >>> x = 20 # This is comment with expression line
Delimiters :- Delimiters can be defined as a sequence of one or more characters that is used to specify the boundary between separate independent regions in plain text or other data streams.
Example :- Delimiter example is comma(,). for some method like split(), default limiter is whitespace.
Data :-
Example :- Delimiter example is comma(,). for some method like split(), default limiter is whitespace.
Data :-
- The data we manipulate in Python consists of objects and names.
- Each object in Python has three key attributes: a type, a value & an id.
Data Types :-
No comments:
Post a Comment