Lab Assignment 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Python Programming

Lab Assignment 2
Note: While writing programs write comments also at appropriate places.
Method Description
capitalize() Converts the first character to upper case
casefold() Converts string into lower case
center() Returns a centered string
count() Returns the number of times a specified value occurs in a string
encode() Returns an encoded version of the string
endswith() Returns true if the string ends with the specified value
expandtabs() Sets the tab size of the string
find() Searches the string for a specified value and returns the position of where it was
found
format() Formats specified values in a string
format_map() Formats specified values in a string
index() Searches the string for a specified value and returns the position of where it was
found
isalnum() Returns True if all characters in the string are alphanumeric
isalpha() Returns True if all characters in the string are in the alphabet
isascii() Returns True if all characters in the string are ascii characters
isdecimal() Returns True if all characters in the string are decimals
isdigit() Returns True if all characters in the string are digits
isidentifier() Returns True if the string is an identifier
islower() Returns True if all characters in the string are lower case
isnumeric() Returns True if all characters in the string are numeric
isprintable() Returns True if all characters in the string are printable
isspace() Returns True if all characters in the string are whitespaces
istitle() Returns True if the string follows the rules of a title
isupper() Returns True if all characters in the string are upper case
join() Joins the elements of an iterable to the end of the string
ljust() Returns a left justified version of the string
lower() Converts a string into lower case
lstrip() Returns a left trim version of the string
maketrans() Returns a translation table to be used in translations
partition() Returns a tuple where the string is parted into three parts
replace() Returns a string where a specified value is replaced with a specified value
rfind() Searches the string for a specified value and returns the last position of where it
was found
rindex() Searches the string for a specified value and returns the last position of where it
was found
rjust() Returns a right justified version of the string
rpartition() Returns a tuple where the string is parted into three parts
rsplit() Splits the string at the specified separator, and returns a list
rstrip() Returns a right trim version of the string
split() Splits the string at the specified separator, and returns a list
splitlines() Splits the string at line breaks and returns a list
startswith() Returns true if the string starts with the specified value
strip() Returns a trimmed version of the string
swapcase() Swaps cases, lower case becomes upper case and vice versa
title() Converts the first character of each word to upper case
translate() Returns a translated string
upper() Converts a string into upper case
zfill() Fills the string with a specified number of 0 values at the beginning

Q1. Write a Python program to print the following string in a specific format (see the
output).
Sample String: "Twinkle, twinkle, little star, How I wonder what you are! Up above the world
so high, like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are!"
Output:
Twinkle, twinkle, little star,
How I wonder what you are!
Up above the world so high,
Like a diamond in the sky.
Twinkle, twinkle, little star,
How I wonder what you are!

Q2. Write a Python program which accepts the user's first and last name and print them in
reverse order with the help of format function.
Q3. Write a Python program that accepts an integer (n) and computes the value of
n+nn+nnn. (Hint: nn does not shows multiplication of n and n)
Q4. Write a program to perform addition of two numbers without using + operator.
Q5. Program to enter basic salary and calculate the gross salary of an employee. (Hint:
calculate hra and da as per your choice)
Q6. Swap two numbers without using any other third variable in Python.
a. Use product and division to swap two numbers.
b. Use addition and subtraction swap two numbers.
Q7. Write a python program to create list of strings and check whether their identities are
unique or not. (Without using if)
Q8. Write a program to increase the value of three global variables and use modify values to
create list and then display each value using slicing.
Q9. Write functions to perform swapping of two number.
Q10. Write function to perform arithmetic operations using integers and float numbers.
Q11. Subtract two integer without using minus operator.
Q12. +
Q13. Take multiple input by user in one line and find avg. of them.
Q14. Take two strings like “hello” and “world” with two different variable, write program to
print output without a newline. You have to use two print statement to print in same line.

You might also like