Skip to main content

Python


Hello guy's welcome back for the new post in this section I'll try to complete the basic things which you need to understand about the python. 

And also wanna say that after I start this section I'll complete every single topic about the python in every new post so keep tracking for upcoming post for more information about the python programing.

Just now we start with the definition 


Python:
              Python is a high-level programming language, with applications in numerous areas, including web programming, scripting, scientific computing, and artificial intelligence.
It is very popular and used by organizations such as Google, NASA, the CIA, and Disney.

if you still don't have python installed in your PC so click on the link below:
    
Python 3.8.0




Welcome to Python!

The three major versions of Python are 1.x, 2.x and 3.x. These are subdivided into minor versions, such as 2.7 and 3.3.
Code written for Python 3.x is guaranteed to work in all future versions.
Both Python Version 2.x and 3.x are used currently.
This course covers Python 3.x, but it isn't hard to change from one version to another.
Python has several different implementations, written in various languages.
The version used in this course, CPython, is the most popular by far.


NOTE:An interpreter is a program that runs scripts written in an interpreted language such as Python.


1. Your First Program
Let's start off by creating a short program that displays "Hello world!".
In Python, we use the print statement to output text: 


>>>print('Hello world!')
Hello world! Output: Hello world!


2. Printing Text
The print statement can also be used to output multiple lines of text.
For Example:


>>> print('Hello world!')
Hello world!
>>> print('Hello world!')
Hello world!
>>> print('Spam and eggs...')
Spam and eggs...
3. Simple Operations
(1)
 Python has the capability of carrying out calculations.
Enter a calculation directly into the Python console, and it will output the answer.

>>> 2 + 2
4
>>> 5 + 4 - 3
6

(2) Python also carries out multiplication and division, using an asterisk to indicate multiplication and a forward slash to indicate division.
Use parentheses to determine which operations are performed first.

>>> 2 * (3 + 4)
14
>>> 10 / 2
5.0 (3)
 The minus sign indicates a negative number.
Operations are performed on negative numbers, just as they are on positive ones.

>>> -7
-7
>>> (-7 + 2) * (-4)
20 (4)  Dividing by zero in Python produces an error, as no answer can be calculated.

>>> 11 / 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero NOTE:In Python, the last line of an error message indicates the error's type.Read error messages carefully, as they often tell you how to fix a program!

Other than that if we Divide these operations in Mathematical point of view

1. Arithmetic operators: Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication and division
  1. Operator
    Description Syntax
    + Addition: adds two operands x + y
    - Subtraction: subtracts two operands x - y
    * Multiplication: multiplies two operands x * y
    / Division (float): divides the first operand by the second x / y
    // Division (floor): divides the first operand by the second x // y
    % Modulus: returns the remainder when first operand is divided by the second
    x % y
      # Examples of Arithmetic Operator
      a = 9
      b = 4
        
      # Addition of numbers
      add = a + b
      # Subtraction of numbers 
      sub = a - b
      # Multiplication of number 
      mul = a * b
      # Division(float) of number 
      div1 = a / b
      # Division(floor) of number 
      div2 = a // b
      # Modulo of both number
      mod = a % b
        
      # print results
      print(add)
      print(sub)
      print(mul)
      print(div1)
      print(div2)
      print(mod)
      Output:
      13
      5
      36
      2.25
      2
      1
      2. Relational Operators: Relational operators compares the values. It either returns True or False according to the condition.
      Operator Description Syntax
      > Greater than: True if left operand is greater than the right x > y
      < Less than: True if left operand is less than the right x < y
      == Equal to: True if both operands are equal x == y
      != Not equal to - True if operands are not equal x != y
      >= Greater than or equal to: True if left operand is greater than or equal to the right x >= y
      <= Less than or equal to: True if left operand is less than or equal to the right x <= y
      # Examples of Relational Operators
      a = 13
      b = 33
        
      # a > b is False
      print(a > b)
        
      # a < b is True
      print(a < b)
        
      # a == b is False
      print(a == b)
        
      # a != b is True
      print(a != b)
        
      # a >= b is False
      print(a >= b)
        
      # a <= b is True
      print(a <= b)
      Output:
      False
      True
      False
      True
      False
      True

      3. Logical operators: Logical operators perform Logical AND, Logical OR and Logical NOT operations.
      Operator Description Syntax
      and Logical AND: True if both the operands are true x and y
      or Logical OR: True if either of the operands is true x or y
      not Logical NOT: True if operand is false not x
      # Examples of Logical Operator
      a = True
      b = False
        
      # Print a and b is False
      print(a and b)
        
      # Print a or b is True
      print(a or b)
        
      # Print not a is False
      print(not a)
      Output:
      False
      True
      False
    4. Bitwise operators: Bitwise operators acts on bits and performs bit by bit operation.
      Operator Description Syntax
      & Bitwise AND x & y
      | Bitwise OR x | y
      ~ Bitwise NOT ~x
      ^ Bitwise XOR x ^ y
      >> Bitwise right shift x>>
      << Bitwise left shift x<<
      # Examples of Bitwise operators
      a = 10
      b = 4
        
      # Print bitwise AND operation  
      print(a & b)
        
      # Print bitwise OR operation
      print(a | b)
        
      # Print bitwise NOT operation 
      print(~a)
        
      # print bitwise XOR operation 
      print(a ^ b)
        
      # print bitwise right shift operation 
      print(a >> 2)
        
      # print bitwise left shift operation 
      print(a << 2)
      Output:
      0
      14
      -11
      14
      2
      40
    5. Assignment operators: Assignment operators are used to assign values to the variables.
      Operator Description Syntax
      = Assign value of right side of expression to left side operand x = y + z
      += Add AND: Add right side operand with left side operand and then assign to left operand a+=b     a=a+b
      -= Subtract AND: Subtract right operand from left operand and then assign to left operand a-=b       a=a-b
      *= Multiply AND: Multiply right operand with left operand and then assign to left operand a*=b       a=a*b
      /= Divide AND: Divide left operand with right operand and then assign to left operand a/=b         a=a/b
      %= Modulus AND: Takes modulus using left and right operands and assign result to left operand a%=b   a=a%b
      //= Divide(floor) AND: Divide left operand with right operand and then assign the value(floor) to left operand a//=b       a=a//b
      **= Exponent AND: Calculate exponent(raise power) value using operands and assign value to left operand a**=b     a=a**b
      &= Performs Bitwise AND on operands and assign value to left operand a&=b     a=a&b
      |= Performs Bitwise OR on operands and assign value to left operand a|=b         a=a|b
      ^= Performs Bitwise xOR on operands and assign value to left operand a^=b       a=a^b
      >>= Performs Bitwise right shift on operands and assign value to left operand a>>=b     a=a>>b
      <<= Performs Bitwise left shift on operands and assign value to left operand a <<= b                    a= a << b
      6. Special operators: There are some special type of operators like-
    • Identity operators-
      is and is not are the identity operators both are used to check if two values are located on the same part of the memory. Two variables that are equal does not imply that they are identical.
      is          True if the operands are identical 
      is not      True if the operands are not identical 
    # Examples of Identity operators
    a1 = 3
    b1 = 3
    a2 = 'GeeksforGeeks'
    b2 = 'GeeksforGeeks'
    a3 = [1,2,3]
    b3 = [1,2,3]
      
      
    print(a1 is not b1)
      
      
    print(a2 is b2)
      
    # Output is False, since lists are mutable.
    print(a3 is b3)
    Output:
    False
    True
    False

    I think this much information is enough for you to clearly understand about the Basic operations in python which we'll conduct.

    In upcoming post I'll try to complete the "Float" in python so keep following and sharing the knowledge. 





Comments

Popular posts from this blog

Some more abbreviations:-

Some more abbreviations:-  PDF        The Portable Document Format (PDF) (redundantly: PDF format) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as ISO 32000 in 2008, and no longer requires any royalties for its implementation. 2. CD  Compact disc (CD) is a digital optical disc data storage format that was co-developed by Philips and Sony and released in 1982. The format was originally developed to store and play only sound recordings (CD-DA) but was later adapted for storage of data (CD-ROM). Several other formats were further derived from these, including write-once audio and data st

Floats

Floats Floats are used in Python to represent numbers that aren't integers. Some examples of numbers that are represented as floats are 0.5 and -7.8237591. They can be created directly by entering a number with a decimal point, or by using operations such as division on integers. Extra zeros at the number's end are ignored.  >>> 3/4 0.75 >>> 9.8765000 9.8765 Computers can't store floats perfectly accurately, in the same way that we can't write down the complete decimal expansion of 1/3 (0.3333333333333333...). Keep this in mind, because it often leads to infuriating bugs!  As you saw previously, dividing any two integers produces a float. A float is also produced by running an operation on two floats, or on a float and an integer. >>> 8 / 2 4.0 >>> 6 * 7.0 42.0 >>> 4 + 1.65 5.65 A float can be added to an integer, because Python silently converts the integer to a float. However, this implicit conversion is

Tweet's