Uploaded on Dec 9, 2020
We at CodeKaroYaaro empowering every kid to become a Computer Science Expert by teaching them to develop mobile apps, gaming apps, websites, web applications and AI-Powered Mobile Apps. Gone are the days when programming languages and learning how to code was like a top-secret for kids, parents were like not to give them electronic gadgets for exploring the uses of it. And mobile phones, tablets, computers, and laptops all were kept away from kids' surroundings. By the time the technology revolution took place everything had changed from traditional to digital platforms. Now, Websites, Mobile Apps, Web Apps, Gaming Apps are part of our daily life. We all are digitally connected with social sites like Facebook, Twitter, Instagram, LinkedIn, etc. We are utilizing technology for our purpose, we should also propose opportunities for learning how to code to kids so that they can explore more into technology via our programming and coding courses. Our objective is very clear towards kids' development by teaching them programming languages, block coding, python coding, etc., and opening a new world of opportunities with fun and creativity for them. We are always inspiring our little coders for learning to code in different coding languages like HTML, Java python for kids. And we will arrange more Coding Winter and Summer Camps and coding quizzes, competitions, online quizzes, and programs for kids from time to time.
CodeKaroYaaro PPT python (4)
GETTING TO
KNOW YOUR
TE A PYTCHON PRHOGRAMEMING PART-(4) R
ADD YOUR NAME HERE
COMPOUND DATA: LIST, TUPLE,DICTIONARY
What are tuples in Python?
A tuple is another sequence data type that is similar to the list. A tuple consists ofa
number of values separated by commas. Unlike lists, however, tuples are enclosed within
parentheses.
What is the difference between tuples and lists in Python?
The main differences between lists and tuples are – Lists are enclosed in brackets ( [ ] )
and their elements and size can be changed, while tuples are enclosed in parentheses
( ( ) ) and cannot be updated. Tuples can be thought of as read- only lists.
What are Python's dictionaries?
Python's dictionaries are kind of hash table type. They work like associative arrays or
hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any
Python type, but are usually numbers or strings. Values, on the other hand, can be any
arbitrary Python object.
Explain how to create a dictionary in python?
Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed
using square braces ([]).
dict = {}
dict['one'] = "This is one”
dict[2] = "This is two”
tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
Explain what is range() function and how it is used in lists?
The range function returns an immutable sequence object of integers between the given
start integer to the stop integer
range(start,stop,[step])
>>>f
or I
In
range(1,10,2):
print(i,end=‖―) 1 35 7 9
How lists are updated in Python?
The append() method is used to add elements to a list.
Syntax:
list.append(obj)
List=[123,‘VR
B‘] List.append(2017)
Print(―
Updat
ed
List:1,
List)
Output: Updated List: [123,‘VRB‘,2017]
Write a few methods that are used in Python Lists.
• append()- add an element to end of list
• insert()- insert an item at the defined index
• remove()- removes an item from the list
• clear()- removes all items from the list
• reverse()- reverse the order of items in the list
What are the advantages of Tuple over List?
• Tuple is used for heterogeneous data types and list is used for
homogeneous data types.
• Since tuple are immutable, iterating through tuple is faster than with list.
• Tuples that contain immutable elements can be used as key for
dictionary.
• Implementing data that doesn‘t change as a tuple remains write-
protected
What is indexing and negative indexing in Tuple?
The index operator is used to access an item in a tuple where index starts from 0.
Python also allows negative indexing where the index of -1 refers to the last item,
-2 to the second last item and so on.
>>>my_tuple=(‗p‘,‘y‘,‘t‘,‘h‘,‘o‘,‘n‘)
>>>print(my_tuple[5]
) n
>>>print(m
y_tuple[-
6]) p
What is the output of print tuple[1:3] if tuple = ( 'abcd', 786 ,
2.23, 'john', 70.2)?
In the given command, tuple[1:3] is accessing the items in tuple using indexing.
It will print elements starting from 2nd
till 3rd. Output will be (786, 2.23).
What are the methods that are used in Python Tuple?
Methods that add items or remove items are not available with tuple. Only the
following two methods are available:
• count(x)- returns the number of items that is equal to x
• index(x)- returns index of first item that is equal to x
Is tuple comparison possible? Explain how with
example.
The standard comparisons (‗‘,‘=‘,‘==‘) work exactly the same
among tuple objects. The tuple objects are compared element by element.
>>>a=(1,2,3,4,5)
>>>b=(9,8,7,6,5)
>>>a<
b True
What are the built-in functions that are used in Tuple?
• all()- returns true if all elements of the tuple are true or if tuple is empty
• any()- returns true if any element of tuple is true
• len()- returns the length in the tuple
• max()- returns the largest item in tuple
• min()- returns the smallest item in tuple
• sum()- returns the sum of all elements in tuple
Explain what is dictionary and how it is created in Python?
Dictionaries are similar to other compound types except that they can use any
immutable type as an index. One way to create a dictionary is to start with the
empty dictionary and add elements. The empty dictionary is denoted {}:
>>> eng2sp = {}
>>> eng2sp[‘one‘] = ‘uno‘
>>> eng2sp[‘two‘] = ‘dos‘
What is meant by key-value pairs in a dictionary?
The elements of a dictionary appear in a comma-separated list. Each entry
contains an index and a value separated by a colon. In a dictionary, the
indices are called keys, so the elements are called key-value pairs.>>> print
eng2sp {‘one‘: ‘uno‘, ‘two‘: ‘dos‘}
How does del operation work on dictionaries?Give an
example.
The del statement removes a key-value pair from a dictionary. For example,
the following dictionary contains the names of various fruits and the number
of each fruit in stock:
>>> inventory = {‘apples‘: 430, ‘bananas‘: 312, ‘oranges‘: 525, ‘pears‘: 217}
>>> print inventory {‘oranges‘: 525, ‘apples‘: 430, ‘pears‘: 217, ‘bananas‘:
312}
If someone buys all of the pears, we can remove the entry from the dictionary:
>>> del inventory[‘pears‘]
>>> print inventory
{‘oranges‘: 525, ‘apples‘: 430, ‘bananas‘: 312}
We are going to have a great year learning
toSgetLheIr!For moreD inforEmatio n TpleasIe cTontacEt us at :
https://www.codekaroyaaro.com/
[email protected]
7972289701
https://www.facebook.com/codekaro
yaaro
https://www.instagram.com/codekaroyaaro/?
igshid=1nb6afsffwzd
https://www.linkedin.com/company/codekar
oyaaro
https://www.youtube.com/channel/UC0GUyPIpdDVJQMug
EtkH8Pw
Comments