Posts

Escape sequence in python

  Sequence of character after backslash ‘\’ are called escape sequence character. Escape sequence character comprises of more than on character but represent one character when used within the string. Some of the commonly used escape sequence characters are :- ‘\\’ Backslash character ‘\” single quote character ‘\n’ Newline character ‘\t’ Tab character Example :- # for backslash print ( "This is a\\ string" ) # for single quote in string print ( "This is \'a\' string" ) #for tab print ( "This is a\t string" ) # for line break print ( "This is a\n string" ) Python Copy Output :- This is a\ string This is 'a' string This is a string This is a ...

String In Python

  A string is a sequence if characters. It can be declared in python by using double quotes. String are immutable i.e, They can not be changed. We can primary write string in three ways :- Single quote string  :- ‘Codeupon’ Double quote string :-  “Codeupon” Triple quote string :-  ”’Codeupon”’ String slicing A string in python can be sliced for getting a part of the string. Syntax :- variable_name [start index : end index : gap/skip index] Example #1 :-  Slicing the string str = "codeupon" print ( str [ 0 : 5 ] ) Python Copy Output :- codeu Markup Copy Example #2 :-  Slicing string with skip values str = "codeupon" print ( str [ 0 : 5 : 2 ] ) Python Copy Output :- cdu Python Copy Example #3 :-  Reversing a string str = "codeupon" print ( str [ : : - 1 ] ) Python Copy Output :- nopuedoc Python Copy String Functions Some of the mostly used functions to perform operation on or manipulate strings are :- len () Function :-  This function is...

( == ) and Is Operator in Python

  ( == ) Double equal to operator The double equal operator compares the values of both the operands and checks for value equality. Example #1:- a = 5 b = 5 if a == b : print ( True ) else : print ( False ) Python Copy Output :- True Markup Copy is operator is operator checks whether both operands refer to the same object or not means both refers to same memory location or not. It check only both variables refer to same memory location.\ Example #2 :- a = 5 b = 3 if a is b: print(True) else: print(False) Markup Copy Output :- False Markup Copy It return False because the value of the variables are same but the memory location of both variables are different. I hope you understand the concept of ( == ) and is operator in python. If you have any query or suggestion please do a comment. Thank you.

Any and All Operator In Python

Any operator This operator return True if any of the items in the list is True. It return False if empty or all the items are False. Example #1:- print ( any ( [ False , False , False ] ) ) Python Copy Output :- False Markup Copy Example #2:- print ( any ( [ False , True , False ] ) ) Python Copy Output :- True Markup Copy Example #3 :- Program using any operator list1 = [ ] list2 = [ ] for i in range ( 10 ) : list1 . append ( 4 * i ) for i in range ( 10 ) : c = list1 [ i ] % 5 == 0 list2 . append ( c ) print ( list2 ) print ( any ( list2 ) ) Python Copy Output :- [True, False, False, False, False, True, False, False, False, False] True Markup Copy   Explanation :-  Its return True because in the list its find one item is True All   operator This all operator return True if all the items of the list are True, if any one of them is False then it will retur...