Saturday, 16 February 2019

Data Types and Operators in Python

The Data types in Python are :
  • boolean
  • byte
  • list
  • tuple
  • dict
  • Complex Number
  • float
  • long
  • string
Primitive data types are stored in stack memory.

boolean:
Valid values: true, false
Default value: false
Size: 1 bit

Python Code:
isEnabled = True

Byte:

Python Code:
b'Python'

List:

Python Code:
listOfFruits = ["apples", "mango", "bananas"]

Tuple:

Python Code:
listOfVegetables = ("carrot", "brinjal", "cauliflower")

Dict:

Python Code:
numberDictionary = {"ONE" : 1, "TWO" :2}

Complex Number: 

Python Code:
z = 2+3j

float:
Python Code:
x = 2.3

long:
Python Code:
bigValue = 1094324242344L

string:
Python Code
x = "The Quick Brown Fox Jumps Over The Lazy Dog"


Python Operators: 

Listed below are various operators available in Python. A brief description is provide with the operators and an example of most commonly used operators is provided to end this blog.

Multiplication/division operators:

* : It multiples the left and right operand and returns the result.
% : Modulo operator. Divides the left operand with the right operand and returns the remainder.
/  : Division Operator. Divides the left operand and returns the result.

Additional / Subtraction :

+ : Addition Operator. Adds the left operand with the right operand and returns the result.
- : Subtraction Operator. Subtracts the left operand and right operand and returns the result.

Shift Operators :

<< : Left Shift Operator. Moves the left operand to the left by the number of bits specified by the right operand.
>> : Right Shift Operator. Moves the left operand to the left by the number of bits specified by the right operand.

Relational Operators :

< : Less than Operator. Check if the left operand is less than the right operand. Return True or False.
> : Greater than Operator. Check if the left operand is greater than the right operand. Return True or False.
>= : Greater than or equal to. Check if the left operand is greater than or equal to the right operand . Return True or False.
is : Instance of Operator. Check if the left operand is instance of right operand. Example: Is Dog Animal. True. Is Dog Plant. False.


Equality :

== : Check if left operand is equal to the right operand. Return True or False.
!= : Check if left operand is not equal to the right operand. Return True or False.

Bitwise AND :
& : Bitwise AND Operator. If bit exists in both left and right operand, copy the bit to the result.

Bitwise exclusive OR :
^ : Bitwise XOR Operator. If bit is set in either left or right operand but not in both, copy the bit to the result.

Bitwise inclusive OR :
| : Bitwise OR Operator. If bit exists in either left to right operand is true, the result will be true else false.

Logical AND :
and : Logical AND Operator. If both left and right operand is true, the result will be true else false.

Logical OR :
or : Logical OR Operator. If Either left or right operand is true, the resultwill be true or false.

Assignment Operator :

= : Assignment operator. Assign the right operand to the left operand.
+= : Add plus assignment operator. Adds the left and right operand AND assigns the result to the left operand
-= : Subtract plus assignment operator. Subtract the left and right operand AND assigns the result to the left operand.
*= : Multiples plus assignment operator. Multiplies the left and right operand AND assigns the result to the left operand.
/= : Divides plus assignment operator. Divides the left and right operand And assigns the result to the left operand.
%= : Modulo plus assignment operator. Divides the left and right operand AND assigns the remainder to the left operand.
&= : Bitwise AND plus assignment operator.
^= : Bitwise OR plus assignment operator.
>>= : Right shift plus assignment operator.

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (49) AI (34) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (173) C (77) C# (12) C++ (82) Course (67) Coursera (226) Cybersecurity (24) data management (11) Data Science (128) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (59) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (3) Pandas (4) PHP (20) Projects (29) Python (929) Python Coding Challenge (351) Python Quiz (21) Python Tips (2) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (3) Software (17) SQL (42) UX Research (1) web application (8) Web development (2) web scraping (2)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses