GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pythonbasic/tuple_example.py at main · programmingwithmohammed/pythonbasic

Expand file tree

/

tuple_example.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
38 lines (25 loc) · 1.21 KB
/

tuple_example.py

Copy path

File metadata and controls

38 lines (25 loc) · 1.21 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 27 18:08:16 2021
@author: mjach
"""
'''How to create one item and empty tuple'''
my_tuple = ()
print('To see what type it is :', type(my_tuple))
'''please make sure if you create one item tuple
must be added one comma at the end other wise it will not work'''
my_tuple_with_one_item = (1,)
print('To find out what type is it:',type(my_tuple_with_one_item))
'''creating tuple with multiple items'''
student_result_details = ('Hasan','Math', 80, 'geography', 90, 'science', 95, 'total', 265 )
print('Student result details :', student_result_details)
'''How to access tuple items. if index is too big compare to tuple index size
then it will give error message. tuple index out of range
'''
print('Item access by the index number :', student_result_details[0])
'''Assinging tuple items- unpacking'''
studentName,subjectMath, mathMarks, subjectGegraphy, geographyMarks, subjectScience, scienceMarks , total, totalMarks = student_result_details
print('Studnet subject result grade :', studentName, totalMarks)
'''But we can not assign new item as we can not change them '''
#we will get a type error 'tuple' object does not support item assignment
student_result_details[0] = 'English'
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.