✨ Introduction to Python ✨
In this blog, I m going to explain about basics of python.
Contents of this blog:
- What is Python?
- Features Of Python
- Basic Data Type In python
- Summary for data types
- How to print something on console ?
- How to take input in python ?
- Comments in Python
- Type conversion in Python
What is Python?
Python is a High level, interpreted, general-purpose programming language It was developed by Mr. Guido von Rossum in 1991. It is an interactive language.
Features Of Python :-
- Open source : Source code can be modified and redistributed as per user requirement.
- Dynamic typed language : We don’t need to give the data type while writing the program, python will understand
on it’s own.
n=20 -> here, python will understand that n is of type integer.
- Interpreted language : python is interpreted language. Python executes the code line by line if any error occurred, it halts the program.
- Cross platform : The code working on Windows will also work on MAC and Unix, So it is cross platform.
- It has wide range of libraries.
- OOPS : python supports OOP(Object Oriented Programming) and POP(Procedure oriented Programming) both.
- It is easy to learn.
Lets Start Basic of Python Programming:
* Identifiers :-
An identifier is a name that identifies anything like classes, variables, objects.
Rule for Identifiers in Python :-
- Identifier can’t begin with digits. e.g. : 2name = “ram”(this is wrong).
- The identifier can only begin with underscore ( _ )or alphabets. e.g. n = 20, _a = 33 etc.
- Uppercase and lowercase identifiers are different. e.g. n = 20, N = 20 (both are different identifiers).
- Identifiers can have numbers, alphabets and underscore( _ ).
- No keyword should be used an identifier.
Examples of valid Identifiers: a_123, _a123 , weight, WEIGHT etc.
Examples of invalid Identifiers: 123a_, +123a_ etc.
- Keywords : -
keywords are reserved name or predefined name have some special meaning.
e.g. : if, else, for, while, in, pass, continue, True, False etc. many more.
- Variable : -
Variables are containers for storing data values.
Syntax : var_name=value;
e.g. : num =10, name = “Rahul”, f_num = 2.5 .
Basic Data Type In python:
- Integer : -
Representation : -
2. Floating-Point Numbers : -
float values are specified with a decimal point. character
E followed by a positive or negative integer may be appended to specify scientific notation.
3. Complex Numbers : -
Complex numbers are specified as
<real part>+<imaginary part>j.
e.g. : 3 + 4 j, 5 + 7j etc.
4. Boolean : -
Objects of Boolean type may have one of two values,
5. String : -
Strings are sequences of character.
The string type in Python is called
String is created by using either single or double quotes.
e.g. : firstName = “Rahul”
lastName = ‘Kumar’
Summary for data types: -
Note : type() -> gives type of variable
How to print something on console ?
by using print() function.
' ', end=’\n’, file=sys.stdout, flush=False)
- objects : object to the printed. * indicates that there may be more than one object
- sep: objects are separated by sep. Default value:
' ' (optional)
- end: end is printed at last
- file : must be an object with write(string) method. If omitted,
sys.stdoutwill be used which prints objects on the screen.
- flush: If True, the stream is forcibly flushed. Default value:
How to take input in python ?
BY using input() function.
input() function by default takes input anything as string.
if we have to take input integer, floating number and boolean the we need to type cast to desire data type :
Comments in Python:
- Single line comment :
use -> #
2. Multiline comment :
use -> “ “ “ ” ” ” or ‘‘‘ ’’’
Type conversion in Python :
There are two types of type conversion in general:
- Implicit type conversion (done automatically by compiler).
- Explicit type conversion (done exclusively by the user).
Python only supports explicit type conversion.
num = “10” # string
num = int(num) #converting num(string) into int.
Thanks for reading this…….