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.
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.
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.
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
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...')
For Example:
>>> print('Hello world!')
Hello world!
>>> print('Hello world!')
Hello world!
>>> print('Spam and eggs...')
Spam and eggs...
3. Simple Operations
(1)
(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.
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.
>>> 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
-
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 % yOutput: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 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 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<< 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
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. - Identity operators-
Comments
Post a Comment