What’s Variable?

Variables are like containers store some data, pull it out later they can hold all sorts of things like numbers, boeleans, and strings

How we can assign variables :

Normal assigning


X=100   (Assign 100 to X)
Man=45 (Assign 45 to Man)
Print (Man + X) (when you print the this you’ll get below answer)
101

Assigning to other variables


Women=100 (first we assign 100 to Women variable)
Lady=women (now we assigned women to Lady Variable 
			so now lady have women's value that mean now lady contain value 100)
Women=200 (but again we reassigning the women value of women)

Now if we print the women we will get 200 as answer and if we print Lady we will get 100 as answer Assigned at the same time as other variables


a, b, c =5, 10, 15 (Assigning multiple value to multiple variable)

Note:

  • Variables are always assigned with the variable name on the left and the value on the right of equals sign.
  • Variables must be assigned before they can be used.

Naming Restrictions

In Python, you can name you variables whatever you want, with some restrictions:

  • Variables must start with a letter or underscore
  • 
    _cats is right 
    2cars is wrong
    

  • The rest of the name must consist of letters, numbers, or underscore
  • 
    Cats2 is right 
    hey@you is wrong because of the @
    

  • Names are case sensitive
  • 
    CATS and Cats are not equal
    

Naming Conventions

Most python programmers prefer to use standard style conventions when naming things

  • Most variables should be snake_case(underscores between words)
  • Most variables should be also be lowercase with some exceptions: CAPITAL_SNAKE_CASE usually refers to constants (e.g. PI=3.14). UpeerCamelCase usually refers to class (more on that later)
  • 
    CATS and Cats are not equal
    

  • Variables that start and end with two underscores (called 'dunder' for double underscore) are supposed to be private or left alone.

Data Types

What's Boolean?

In computer science, the Boolean data type is a data type that has one of two possible values (use the constants TRUE and FALSE that evaluate to 1 and 0 respectively), intended to represent the two truth values of logic and Boolean algebra.

It is named after George Boole, who first defined an algebraic system of logic in the mid-19th century.

What’s string? :

A string is generally considered a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding.

String may also denote more general arrays or other sequence (or list) data types and structures.


X=’8’
Type(x)
<String>

What’s dictionary? :

Python - Dictionary. ... An empty dictionary without any items is written with just two curly braces, like this: {}. Keys are unique within a dictionary while values may not be.

The values of a dictionary can be of any type, but the keys must be of an immutable data type such as strings, numbers, or tuples.

What's Integer

An integer (pronounced IN-tuh-jer) is a whole number (not a fractional number) that can be positive, negative, or zero. Examples of integers are: -5, 1, 5, 8, 97, and 3,043.

Examples of numbers that are not integers are: -1.43, 1 3/4, 3.14, .09, and 5,643.1.

What's Float :

The term floating point refers to the fact that a number's radix point (decimal point, or, more commonly in computers, binary point) can "float"; that is, it can be placed anywhere relative to the significant digits of the number.

Different between Integer and float :

Integers and floats are two different kinds of numerical data. An integer (more commonly called an int) is a number without a decimal point.

A float is a floating-point number, which means it is a number that has a decimal place. Floats are used when more precision is needed.


type(9)
<Class 'int'>
Type(9.0)
<<class 'float'>
Type(10200)
<Class 'int'>
Type(0.003)
<class 'float'>

Note: When you combine the integer with float result will be float for example


type(9)
1 +1.0
2.0 (not 2 result will be 2.0)

Numbers Basic Math

In this section we are going to see about operators Addition, subtraction, division and multiplication.

What’s Addition (+)? :

An addition is the act of adding something new, like a baby — a new addition to your family — or what you do in math class: the addition of columns of numbers to get the sum. The noun addition comes from the Old French word addition, meaning "that which is added."

What’s subtraction (-)? :

Subtraction is an arithmetic operation that represents the operation of removing objects from a collection. ...Subtraction is signified by the minus sign (−). For example, in the adjacent picture, there are 5 − 2 apples—meaning 5 apples with 2 taken away, which is a total of 3 apples.

What’s Division (/)?

The operation inverse to multiplication; the finding of a quantity, the quotient, that when multiplied by a given quantity, the divisor, gives another given quantity, the dividend; the process of ascertaining how many times one number or quantity is contained in another.

What’s Multiplication (*)? :

A mathematical operation performed on a pair of numbers in order to derive a third number called a product. For positive integers, multiplication consists of adding a number (the multiplicand) to itself a specified number of times. Thus multiplying 6 by 3 means adding 6 to itself three times.

Priority of Operations :

Note: When we use all the mathematical operation at the same time the order we should follow is.

  • Parentheses
  • Exponents
  • Multiplication
  • Division
  • Addition
  • Subtraction

Complex Numeric Operations

In this section we are going to see about operators Exponentiation Modulo and Integer Division.

What's Exponentiation (**)?

Exponentiation is an expression that involves exponents, where an exponent is mathematical shorthand representing how many times a number is multiplied against itself.

When the base, the number multiplied against itself, is a positive integer, a whole number greater than zero, exponentiation is also a mathematical operation that involves a finite number of multiplication problems involving the same number or variable.

For example: 4** 8 = 65536

What's modulo (%)? :

Respect to or using a modulus of a specified number. Two numbers are congruent modulo a given number if they give the same remainder when divided by that number. Example: 10 % 3 = 1

What's Integer division (//)? :

Integer division is division in which the fractional part (remainder) is discarded is called integer division and is sometimes denoted. Integer division can be defined as, where "/" denotes normal division and is the floor function

Usually when you 10/3 you’ll get 3.333 as result but when you want only the integer as result you can use this for example 10//3 you’ll get 3 as result.

None

None' is Python's equivalent of NULL in C and C++, It signifies that the variable doesn't hold any value as of now.


myVar = None
print(myVar)

#output
The output of this program would be:
None
You could also change the value of the variable at a later point in time.


myVar = None
print(myVar)
myVar = "foo"
print(myVar)

#The output of this program would be:
None
foo

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Selenium Online Training : Our next online training course for Selenium with Java starts from 17th December 2018.

You can attend first 3 classes for free, the total course fee is INR 10,000

The course time would be 8.00 PM(IST) for the first three classes

If you are interested to learn, then you can join the course by sending email to chercher.tech@gmail.com

or Register below


 
Join My Facebook Group
Join Group