Skip to main content

Posts

Showing posts from September, 2021

Python String Count(), len() , find() Built in Functions

  in python count() function is used to get total count of given element  in a string. the counting starts from string starts to till end. Ex. str1 = "Saransh" str_count = str1.count("a") print("the count of 'a'is",str_count) output String len() Ex. x = "Hello,Saransh" print(len(x)) output 13 String find() with len() // without space Ex. txt = "HelloMynameisSaransh" print(txt.find("e")) print(txt.find("Saransh")) print(txt.find("h")) print(len(txt)) output

Python Username and Password using if .. else

 Easy ways to check username and password by using simple if else statement. Ex. username = "saransh" password = "Saransh77" x = input("enter your username- ") y = input("enter your password- ") if x == username: if y == password: print("Okay Right..!") else: print("please enter correct username or password.") OUTPUT

Python If...else Statement

  Simple If  Statement x = 23 if x > 0: print("x is positive value") print("this is always printed") x = -1 if x > 0: print(x, "is positive number") print("this is also always printed") Output If...Else statement a = -7 if a > 0: print(a, " is positive") else: print(a," is Negative") output

Python Input and Type Casting.

  Main Key Points input() // for get userinput value int()    //  eval() // float()  // x =input("Enter Your age-") // 23 print(x) output 23 int() Type cast x = int(input("Enter Your age-")) // only enter integer value print(x) output 23 float() type cast x = float(input("Enter Your age-")) // 44 print(x) output 44.0 eval() type casting - any types of value converts x = eval(input("Enter Your age-")) // enter- 0b1111( 15 binary number) print(x) output 15

Python Identity Operators

  Python Identity Operators. Operators Description Example Is Returns True If Both Same A Is B Is Not Return True If Both Are Not Same A Is Not B Ex. X = 22 Y = 25 print(X is Y) print(X == Y) print(X is not Y) print(X != Y) OUTPUT False False True True

Best Python tutorials For Beginners.

Python is a interpreted high level programming language. Python is a simple , object oriented, general purpose programming language. Python is a easy to use and learn versatile programming language. #Python Variables Variable is used to store value and refer to memory locations. x  =  23 // where "x" is variable. // 23 is x's value. #Python Data Types here , variable can hold a values and every variable has a data type. you can check data type using " type() " Function. a = 77 // integer data type x = "Saransh" // string  y = 77.7 // float  *Python has a standard data types Boolean  set  Dictionary  Numbers

Reverse String In Python By Simple Methods

  x = "Code By Saransh" y = x[::-1] print(y) OUTPUT hsnaraS yB edoC

Membership operators in Python

  x = "Saransh" print('S'in x) OUTPUT TRUE x = "Saransh" print('v'in x) OUTPUT FALSE # sentences case (h ,H) x = "Saransh" print('H'in x) output False x = "xpple" if "A" in x: print("yes a is found") else: print("No,not found") OutPut: No,not found   x = "Apple" if "A" in x: print("yes a is found") else: print("No,not found") OutPut yes a is found