Skip to main content

Character Case Swapping (PCTS)

 Python Codes The Series -1


©Photo by wiki commons




Not only in Python but also in the day-to-day life, the letters in English alphabets are characterized into two cases viz. upper case and lower case. Our first program will be a general fun program for the beginners. In this program, we will learn to swap the cases of the letters of English alphabets being entered by the user with the help of a few lines of Python code.

For example: If the user enters: "hoLa AmIGo", the python program would convert this string into "HOlA aMigO" .

The Program is noted below:

string=input("Enter a string :")
length=len(string)
s=''
for i in range(length):
    if string[i].islower():
        s=s+string[i].upper()
    elif string[i].isupper():
        s=s+string[i].lower()
    else:
        s=s+string[i]
    print(s)

FOR QUICK REFERENCE:
The len() function gives the length of the string and the the input() function takes input from the user.

Hope you like it 😁 and any positive critic is most welcome into my blog 😉.


©SGPython

Comments

Popular posts from this blog

Type-Casting And Dynamic-Typing

Python is equipped with some of the amazing and easy to use methods which are already built-in keeping the ease of understanding and fun-to-learn. Some of these amazing properties are going to be discussed today in the blog. Type-Casting Typecasting is one of the simple topics of Python which which is very much easy to understand yet is very efficient in the day-to-day lives of Python programmers. Def:  The explicit conversion of an operand to a specific type is called  typecasting. Explicit conversion refers to the type of conversion of datatype into which the user wants to change his or her expression into. Note that these types of conversion are user defined. Typecasting in Python can be explained as follows:                         <datatype> (expression) where <datatype> refers to the datatype into which the user wants to type-cast. Example:  When we use input() function, Python alwa...

Factorial of a Number by a User-Defined Function (PCTS)

 Factorial of a Number There are a number of ways to find the factorial of a number (obviously, it going to a whole number 😆). Out of all of them today, I'm going to show you the user-defined code I created to find the factorial of any whole number. Trust me, it's cool 😎 just give it a try...

For Loops

 The for loop By  polygraphus  on  shutterstock Def: The for loop is also known as the counting loop and is designed to process the items of any sequence, such as a list or a string, one by one. General form of for loop: The general form of the for loop is given below:      for <variable> in <sequence>:          statements to repeat