0% found this document useful (0 votes)
2K views

PYthon Class 15 Telugu

This document discusses default values and operators for strings in Python. It covers: 1) Default start, end, and step values for forward and backward slicing of strings. 2) The + and * operators for string concatenation and repetition. 3) Membership operators like in and not in to check if a substring is in a string. 4) Comparison of strings based on alphabetical order using comparison operators. 5) Common string handling methods like upper(), lower(), and len() to manipulate case and get length.

Uploaded by

THE KING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

PYthon Class 15 Telugu

This document discusses default values and operators for strings in Python. It covers: 1) Default start, end, and step values for forward and backward slicing of strings. 2) The + and * operators for string concatenation and repetition. 3) Membership operators like in and not in to check if a substring is in a string. 4) Comparison of strings based on alphabetical order using comparison operators. 5) Common string handling methods like upper(), lower(), and len() to manipulate case and get length.

Uploaded by

THE KING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

Python Class 15

~~~~~~~~~~~~~~~~~~~~

Default Values
~~~~~~~~~~~~~~~~~~~~~~

For Forward Direction


--------------------------

begining|starting value = 0
Ending = Length of the string
Step|changing value = +1

For Backward Direction


----------------------------

Starting value | Begining Value = -1 (Index Position)

Ending Value = -(Length of string + 1)

eg:

s='abcdefghij'

s[1:8:2] ==> 'bdfh'

s[::-1] ==> 'jihgfedcba'

s[::1] ==> 'abcdefghij'

s[7:4:-1] ==> 'hgf'

s[3:7:-1] ==> ''

s[5:0:1] ==> ''

s[9:0:0] ==> ValueError: slice step cannot be zero

Operators for String


========================

There are two types of operators for strings such as follows:

1. + --> Concatenation
2. * --> Repetition

+(String Concatenation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you join or concatenate two strings then we have to use + Operator

Both the arguments must be strings

eg:
# Program to display your Name and Course
nm=input("Enter Your Name: ")
co=input("Enter Your Course Name: ")
print("Name ="+nm)
print("Course ="+co)

eg:
# Program to display your Name and Course
nm=input("Enter Your Name: ")
age=int(input("Enter Your Age: "))
print("Name ="+nm)
print("Age ="+str(age))

eg:

# Program to display the characters in String in Forward Direction

s="Python is one of the most powerful programming languages in the world"

for i in s[::]:
print(i,end='')

eg:

# Program to display the characters in String in Backward Direction

s="Python is one of the most powerful programming languages in the world"

for i in s[::-1]:
print(i,end='')

* (Repetition)
~~~~~~~~~~~~~~~~~~~~

It is used to display the string multiple number of times based on the users'
requirement

One is string and another one is number(int)

eg:

# Program to display your Name as per the given number of times

nm=input('Enter Your Name : ')


n=int(input("Enter How many Times do you want to display your Name : "))
print(nm*n)

Checking Membership
~~~~~~~~~~~~~~~~~~~~~~~~

We can find the sub_string or character(s) is existed in the given string

There are two types of member ship operators such as follows:

1. in
2. not in
s="where there is a will there is a way"
print('is' in s)
print('are' not in s)
print('is' not in s)
print('are' in s)

String Comparison
~~~~~~~~~~~~~~~~~~~~~

The comparison is done based on alphabetical order


All comparison operators are supported or allowed

eg:

s1=input("Enter First String: ")


s2=input("Enter Second String: ")
if(s1==s2):
print("Two Strings are Equal")
elif(s1>s2):
print("First String is greater than Second String")
else:
print("First String is Less than Second String")

Note:
~~~~~~~~~

In Python 3 all strings are represented in UNICODE(Universal Code)

In Python 2 all strings are represented in 8-bit ASCII(American Standard for


Code for Information Interchange)

To Perform different types of string manipulations, we have to use the string


handling functions

There are different types of String Handling Functions such as follows:

1. upper()
~~~~~~~~~~~~~

It is used to return or display the given string in upper case

Syntax:
-----------

str.upper()

eg:

str="welcome to python programming"


x=str.upper()
print(x)

eg:

str="welcome to python programming"


print("----------Before Changing the given String---------------")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("\n"*2)
print(str)
print("The Length of the string is :",len(str))
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")

print("\n"*5)

print("----------After Changing the given String---------------")


print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("\n"*2)
x=str.upper()
print(x)

print("The Length of the string is : ",len(x))


print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")

2. lower()
-----------------

It is used to return or display the given string in Lower case for

Syntax:
~~~~~~~~~~~~~~

str.lower()

eg:

str="WELCOME TO PYTHON PROGRAMMING"


x=str.lower()
print(x)

You might also like