Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

properties of tuples in python

#Tuples are ordered, indexed collections of data
#Tuples can store duplicate values
#You cannot change the data of a tuple after that you have assigned it the values
#Like lists, it can also store several data items
Comment

create tuples python

values = [a, b, c, 1, 2, 3]

values = tuple(values)

print(values)
Comment

tuples in python

#tuple unpacking
myTuple = ("Tim","9","Smith")
#tuple unpacking allows us to store each tuple element in a variable
#syntax - vars = tuple
"""NOTE: no of vars must equal no of elements in tuple"""
name,age,sirname = myTuple
print(name)
print(age)
print(sirname)
#extra
#this alows us to easily switch values of variables
name,sirname = sirname,name
print(name)
print(sirname)
Comment

Accessing of Tuples in python

#Accessing Tuple
#with Indexing
Tuple1 = tuple("Softhunt")
print("
First element of Tuple: ")
print(Tuple1[1])
 
 
#Tuple unpacking
Tuple1 = ("Python", "Softhunt", "Tutorials")
 
#This line unpack
#values of Tuple1
a, b, c = Tuple1
print("
Values after unpacking: ")
print(a)
print(b)
print(c)
Comment

tuples in python

  strs = ['ccc', 'aaaa', 'd', 'bb']  print sorted(strs, key=len)  ## ['d', 'bb', 'ccc', 'aaaa']
 #the list will be sorted by the length of each argument
Comment

Python Tuples

# Creating an empty Tuple
Tuple1 = ()
print("Initial empty Tuple: ")
print(Tuple1)
 
# Creating a Tuple
# with the use of string
Tuple1 = ('Geeks', 'For')
print("
Tuple with the use of String: ")
print(Tuple1)
 
# Creating a Tuple with
# the use of list
list1 = [1, 2, 4, 5, 6]
print("
Tuple using List: ")
print(tuple(list1))
 
# Creating a Tuple
# with the use of built-in function
Tuple1 = tuple('Geeks')
print("
Tuple with the use of function: ")
print(Tuple1)
Comment

what are tuples in python

#A tuple is essentailly a list with limited uses. They are popular when making variables 
#or containers that you don't want changed, or when making temporary variables.
#A tuple is defined with parentheses.
Comment

python tuples

#!/usr/bin/python

tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print "tup1[0]: ", tup1[0];
print "tup2[1:5]: ", tup2[1:5];
Comment

PREVIOUS NEXT
Code Example
Python :: array concatenation in python 
Python :: python concatenation 
Python :: swap 2 no in one line python 
Python :: python int string float 
Python :: abstract class python 
Python :: dbutils.widgets.get 
Python :: self in python 
Python :: plot scatter and line together 
Python :: python dictionary comprehensions 
Python :: how to make a username system using python 
Python :: variables and data types in python 
Python :: Check and Install appropriate ChromeDriver Version for Selenium Using Python 
Python :: group by list python 
Python :: power in python 
Python :: composition in python 
Python :: python index of lowest value in list 
Python :: check datatype python 
Python :: dataframe cut based on range 
Python :: python convert list of lists of strings to int 
Python :: continue python 
Python :: anagrams string python 
Python :: numpy random 
Python :: how to convert a datatype to another 
Python :: django filter multiple conditions 
Python :: django create view class 
Python :: make gif from images in python 
Python :: loads function in json python 
Python :: fibonacci series in python 
Python :: python gaussian filter 
Python :: largest number python 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =