Introduction to Python
Programming Cycle of Python
Varibles and Datatypes in Python
Input and Output in Python
Operators in Python
Precedence of Operators in Python
Typecasting in Python
If Else in Python
Loops in Python
Break, Continue and Pass in Python
Functions in Python
Default Arguments and Keyword Arguments in Python
Strings in python
Lists in Python
Tuple in Python
Dictionary in Python
Sets in Python
List Comprehension in Python
Unpacking Sequences in Python
Higher Order Functions in Python
Lambda Functions in Python
Sieve of Eratosthenes Algorithm in Python
Linear Search in Python
Binary Search in Python
Selection Sort in Python
Bubble Sort in Python
Insertion Sort in Python
Merge Sort in Python
Varibles and Datatypes in Python
Variable
Variable is a container that stores data. For example, we have a bottle it stores water. Here bottle is
variable and water is data. As we know everything in our system is stored in memory. So we can say, a
variable is a name given to the memory location in which we store data.
Example of Variable:-
n = 100
m = 10.43
s = "Rapid Coders"
Here n, m, s are variables.
Rules for defining the name of variable:
- Variable name can contain alphabets, digits, and underscore
- Variable name can not be any keyword. Keywords are words that have special meanings.
- Variable name should not contain any special character.
- Variable name can only start with alphabet or underscore and can not start with digit
- White spaces are not allowed in variable
Example of valid variable names:- x, y, abc, username, etc.
Note:- Always use meaningfull name for variables. As we know spaces are not allowed so
we use the following naming conventions:
- Camel case:- In this convention first letter of the variable is lowercase and all other words have the first letter in uppercase. Example:- nameOfUser, ageOfPerson.
- Snake case:- In this convention, we use underscore where we need to use space. Example:- name_of_user, age_of_person.
Datatypes
Type of data is called datatype. Before understanding it technically let's understand it generally. In
real life, we have apples, bananas, mango, etc. These all are fruits. Here apples and bananas are data
and fruit is datatype. Technically datatype is a classification that specifies the type of value or
data.
In Python we have the following datatypes:
- Integers:- An integer is a whole number and it can be positive, negative, or zero. Example: 1, 2, 43, 456
- Floating point numbers:- A floating point number, is a positive or negative number with a decimal point. Example: 1.34, 2.543, 43.01, 456.5
- String:- String is a collection of characters. Example: "rapid coders", "Akshay"
- Booleans:- They can have only two values which are True and False.
- None:- This mean nothing. It is used to represent null or no value.
Some other datatypes are:
- List
- Tuple
- set
- dictionary
We will learn about them in further articles.