Skip to main content

Featured

Write a Python Program to find palindrome of a given string

If you reverse the word then you get the same word that word is palindrome. def   palindrome ( str ):     pointer =  str       rev_str =  reversed (pointer)       if   list (pointer) ==  list (rev_str):         print ( "It is palindrome" )       else :         print ( "It is not palindrome" )  palindrome( 'level' ) palindrome( 'madam' ) palindrome( 'life' ) palindrome( 'refer' ) Output:  It is palindrome It is palindrome It is not palindrome It is palindrome

Tuples and dictionary

 Tuple:

          The next sequence type we are going to look is very similar to list. Its tuple. The only difference between tuple and list is tuple are immutable and list are mutable. We cannot edit or manipulate tuple.

Tuple is defined by using parenthesis rather than square bracket. In tuple the iteration run faster than list because tuple values are fixed.

Basically all reading and accessing function like len,min and max stay the same and can be used with tuple. But it is not possible to use any modification 

Example:

tup1=(12, 23, 34, 45, 67)
tup2=(10,20,30,40,50)
tup3=('a',)
print(len(tup1)
print(tup1+tup2)
print(tup3*3)
print(max(tup1))
print(min(tup1))
print(sorted(tup1))
print(sum(tup1,9)

Output:

5
(12, 23, 34, 45, 67, 10, 20, 30, 40, 50)
('a','a','a')
67
12
[12, 23, 34, 45, 67]
190

Hope you understand the program and output if not copy the code and paste it in the console page and see the output

Dictionary:

                  Python dictionary is a container of unordered set of elements like list. The elements are surrounded by curly braces{}. Every entry in this sequence has a key and a respective value where keys are usually numbers or strings and values can be any arbitrary python datatypes. In other programming language this structure is called hash map.

dict={'name':'tech', 'subject':['python','c','c++'],1:[180,198,190]}
print (dict)
print(len(dict))
print(dict.item())
print("print name:", dict ['name'])
print("print subject:", dict['subject'])
dict1={'dob':2001}
dict.update(dict1)
print("update:", dict)
dict.pop('dob')
print("dob removed:", dict)


Output:

Tuple

To get more clear view on the program copy the code and run it in the console page in menu and also make your own datatypes and values to get new experience and fun!!!!!!




Comments

Popular Posts