Skip to main content

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

Comments

Popular posts from this blog

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 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

Reverse String In Python By Simple Methods

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