Python Programming Language

Python Programming Language


Python is one of the most loved programming languages by developers, data scientists, software engineers, and even hackers because of its versatility, flexibility, and object-oriented features.
  • High Level Language
  • Can do complex tasks
  • Easy to Learn
  • Productive coding environment
  • Open source web application
  • Used to create web applications
  • Runs on an interpreter system
Python Training | Python programming, Python logo, Programming ...

Python Variables

Variables are used to store value in it.
Example:- 
                x = 5
                print(x)

Output:- 
                5

Rules for python variables:-
  • Variable name must start with a alphabet or underscore.
  • It can not start with a number.
  • They are case sensitive.
  • They should not contain any special character.
Example:- my_var, hello_world, _myname

Python Comments

Comments in python starts with #. Comments can be used to make more readable. Comment line can be placed anywhere in the program.
Example :- 
                #This is Passable Blog.
                print('Passable Blog')

Output:-
                Passable Blog

Python Operators

Arithmetic Operators

+ Addition (x + y)
- Subtraction (x - y)
* Multiplication (x * y)
/ Division (x/ y)
% Modulus (x % y)
** Exponentiation (x ** y)
// Floor division (x // y)

Comparison operators 

== Equal (x == y)
!= Not equal (x != y)
> Greater than (x > y)
< Less than (x < y)
>= Greater than or equal to (x >= y)
<= Less than or equal to (x <= y

Logical operators 

and Returns True if both statements are true
or Returns True if one of the statements is true
not Reverse the result, returns False if the result is true

Python Built-in functions

all() It returns True if all items in a list are true.
Example:- 
                myblog = [True, True, True,True]
                p = all(myblog)
                print(p)
Output:-
                True

any() - It returns True if any item in a list is true.
Example:- 
                myblog = [True, False, False]
                p = any(mynlog)
                print(p)
Output:- 
                True

bin() - It returns the binary value of a number.
Example:-
                p = bin(3)
Output:-
                0b011

chr() - It returns a character from the specified Unicode code.
Example:- 
                p = chr(97)
                print(p)
Output:-
                a

complex() - It returns a complex number. 
Example:-
                p = complex(5, 2)
                print(p)
Output:-
                5+2j

divmod() - It returns the quotient and the remainder .
Example:- 
                p = divmod(5, 2)
                print(p)
Output:-
                (2, 1)

float() - It returns a floating point number.
Example:-
                p = float(5)
                print(p)
Output:- 
                5.0

hex() - It converts a number into a hexadecimal value.
Example:-
                p = hex(255)
                print(p)
Output:-
                0xff

input() - It allows user to input.
Example:-
                a = input('Enter your name : ')
                print(a)
Output:-
               Enter your name : Ashita
               Ashita

int() - It return integer number.
Example:-
                p = int(5.3)
                print(p)
Output:-
                

len() - It returns the length of the item.
Example:-
                a = ashita
                n = len(a)
                print(n)
Output:-
                6

max() - It returns the largest item in a list.

min() - It returns the smallest item in a list.

oct() - It converts a number into an octal value.
Example:-
                p = oct(12)
                print(p)
Output:-
                0o14

pow() - It returns the value of p to the power of q.
Example:-
                p = pow(2, 4)
                print(p)
Output:-​
                16

print() - It prints the output.
Example:-
                print('This is Passable Blog.')
Output:-
               This is Passable Blog.

round() - It rounds up a number upto the given decimal numbers.
Example:-
                a = 2.45346
                a = round(a,2)
                print(a)
Output:-
                2.45

str() - It returns a string.
Example:-
                a = 2
                print(str(a))
Output:-
                '2'

sum() - It sums the items of a list.
Example:-
                l = [1,2,3,4]
                print(sum(l))
Output:-
                10

type() - It returns the type of an item. 
Example:-
                a = 2
                print(type(a))
Output:-
                <class 'int'>

To be continued..


Comments

Popular posts from this blog

Some tips about the right way to charge your phone

Software Basics

Some unique and weird things about Japan