Count Upper Case and Lower Case Word in a string (Python)

 
Count Upper Case and Lower Case Word in a string     (Python)

def string_test(s):

    d={"UPPER_CASE":0, "LOWER_CASE":0}

    for c in s:

        if c.isupper():

           d["UPPER_CASE"]+=1

        elif c.islower():

           d["LOWER_CASE"]+=1

        else:

           pass

    print ("Original String : ", s)

    print ("No. of Upper case characters : ", d["UPPER_CASE"])

    print ("No. of Lower case Characters : ", d["LOWER_CASE"])


string_test('My Name is Gurpinder Singh')


Output :

Original String :  My Name is Gurpinder Singh

No. of Upper case characters :  4

No. of Lower case Characters :  18



String in alphabetical order in python

 # Python program to sort a string in alphabetical order


string = input("Enter the string : ")

j = 0

str1 = ""

temp = 0

str = list(string)


for i in range(0, len(str)):

for j in range(0, len(str)):

if(str[j] > str[i]):

temp = str[i]

str[i] = str[j]

str[j] = temp

print("The sorted string is : ")

print(str1.join(str))


 Output :

Enter the string : edcba
The sorted string is : 
abcde

Display a set and Remove the Double integer in Python

Display a set and Remove the Double integer in Python  


a = {1,2,2,3,3,3}

print(a)








Output

{1, 2, 3}

Display a Set in Serial Order in Python

 Display a Set in Serial Order in Python


a = {5,2,3,1,4}


# printing set variable

print("a = ", a)


# data type of variable a

print(type(a))


Output 


a =  {1, 2, 3, 4, 5}

<class 'set'>


Display one or more Character of String

 Program Display one or more Character of String 

 


s = 'Hello world!'


# s[4] = 'o'

print("s[4] = ", s[4])


# s[6:11] = 'world'

print("s[6:11] = ", s[6:11])



Output 

s[4] =  o
s[6:11] =  world

String Data Type in Python

 

String Data Type in Python  


s = "This is a string"

print(s)

s = '''A multiline

string'''

print(s)


Output 

This is a string

A multiline

string



Tuble Data Type in Python

 Tuble Data Type in Python 


thistuple = ("apple", "banana", "cherry")

print(thistuple[0])


Output 

apple

List Data Type in Python

 

List  Data Type in Python 


a = [5,10,15,20,25,30,35,40]


# a[2] = 15

print("a[2] = ", a[2])


# a[0:3] = [5, 10, 15]

print("a[0:3] = ", a[0:3])


# a[5:] = [30, 35, 40]

print("a[5:] = ", a[5:])


Output 

a[2] =  15

a[0:3] =  [5, 10, 15]

a[5:] =  [30, 35, 40]

Integer Data Types in Python

 Integer Data Types in Python   


a=5

print(a, "is of type", type(a))


a=2.0

print(a, "is of type", type(a))


a=1+2J

print(a, "is complex number?", isinstance(1+2j,complex))


Output : 

5 is of type <class 'int'>

2.0 is of type <class 'float'>

(1+2j) is complex number? True




Find The Number in Range Python

 

Find The Number  in Range     (Python) 

def test_range(n):

    if n in range(3,9):

        print( " %s is in the range"%str(n))

    else :

        print("The number is outside the given range.")

test_range(2)


Output :

5 is in the range


Count Upper Case and Lower Case Word in a string (Python)

  Count Upper Case and Lower Case Word in a string     (Python) def string_test(s):     d={"UPPER_CASE":0, "LOWER_CASE":...