Python Day -2


What Is Python : Python is an easy to understand ,general purpose programming language

Developed By Guido van Rossum.

Advantages Of Python:

  • Easy To Code
  • Improved Productivity
  • Vast Library Support
  • Lot Of Career Options
  • Used ALmost Everywhere

Operators :

Expression = opreator + operand (X + Y ) here x and y are operands and + is operator

Defination Of Operator -- operators are special symbols, combinations of symbols, or keywords that designate some type of computation

Types Of Operator

  • Arithmetic operators:

       Addition
x = 5
y = 3

print(x + y)
                           
       Subtraction
x = 5
y = 3

print(x - y)        
       Division
x = 12
y = 3

print(x / y)        
       Mod(%)
x = 5
y = 2

print(x % y)        
       Multiplication(*)
x = 5
y = 3

print(x * y)        
       Floor Division(//)
x = 15
y = 2

print(x // y)        
       To the power(**)
x = 2
y = 5

print(x ** y)         

  • Assignment operators

= (x=3)

x = 5
print(x)        
+=(x+=3 same as x= x+3)

x = 5
x += 3
print(x)        
-=(x-=3 same as x = x-3)

x = 5
x -= 3
print(x)        
*=(x*=3 same as x = x*3)

x = 5
x *= 3
print(x)        
/=(x/=3 same as x = x/3)

x = 5
x /= 3
print(x)        

  • Comparison operators

== (True If Equal),

x = 5
y = 3
print(x == y)
# returns False because 5 is not equal to 3        
!=(True If Not Equal)

x = 5
y = 3
print(x != y)
# returns True because 5 is not equal to 3
        
>(Greater Than)

x = 5
y = 3
print(x > y)
# returns True because 5 is greater than 3        
<(Less Than)

x = 5
y = 3
print(x < y)
# returns False because 5 is not less than 3        
>=(Greater Than Equal To)

x = 5
y = 3
print(x >= y)
# returns True because five is greater, or equal, to 3        
<=(Less Than Equal To)

x = 5
y = 3
print(x <= y)
# returns False because 5 is neither less than or equal to 3        

  • Logical operators

and (Returns True if both statements are true)

x = 5
print(x > 3 and x < 10)
# returns True because 5 is greater than 3 AND 5 is less than 10        
or (Returns True if one of the statements is true)

x = 5
print(x > 3 or x < 4)
# returns True because one of the conditions are true (5 is greater than 3, but 5 is not less than 4)
        
not (Reverse the result, returns False if the result is true)

x = 5
print(not(x > 3 and x < 10))
# returns False because not is used to reverse the result        

  • Special Operator

is ( it return true if both object are at the same memory location)

a = 5 
b = 5 
print(id(a))
print(id(b))
print(a is b)
# return true if id(a) and id(b) is same         
 in (Returns True if a sequence with the specified value is present in the object)

x = ["apple", "banana"]
print("banana" in x)
# returns True because a sequence with the value "banana" is in the list        



要查看或添加评论,请登录

Rushikesh J.的更多文章

  • Try and Exception in Python

    Try and Exception in Python

    Exception is the error and is an event, which occur when program statements are executing. It disrupts the flow of…

  • Python Array With Examples

    Python Array With Examples

    Array in Python Array in Python Array is the collection of items having same data type with contiguous memory location.…

  • Python Date Object

    Python Date Object

    We can work with time and date with Python. There are two module in Python time and datetime that used to work with…

  • String Formatting WITH Problems and Solution

    String Formatting WITH Problems and Solution

    What is String Formatting? It is the way to insert custom string or variable in a text (string). Using string…

  • SET Different Methods With Examples

    SET Different Methods With Examples

    SET Method : add() Working: This method is used to add element to set. Syntax: set.

  • Python SET Comprehension With Examples

    Python SET Comprehension With Examples

    What is Comprehension? ?We create a sequence from a given sequence is called comprehension. ?Sequence means list…

  • Difference And Symmetric Difference SET Method With Exercises

    Difference And Symmetric Difference SET Method With Exercises

    SET : Difference Method Working: It return element that are present in first set but same element absent in 2nd set. if…

  • SET : Union Method With Example

    SET : Union Method With Example

    Working: Union method will exclude all the duplicate elements / items in a sets It combine all the items of two or many…

    1 条评论
  • Introduction To Python SET Data Type

    Introduction To Python SET Data Type

    SET is the collection of unordered, unchangeable and unindexable items SET is the mutable data type, because we can add…

  • Python Dictionary Methods

    Python Dictionary Methods

    Python Dictionary Method 1 : clear() Working: It used to remove all the elements from dictionary Syntax: dict.clear()…

社区洞察

其他会员也浏览了