Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python tuple

# tuples are immutable

# initialize tuple
scores = (10, 20, 30)

# check if 10 is in scores tutple
print(10 in scores)

# print all scores in tuple
for score in scores:
    print(scores)

# print length of tuple
print(len(scores))

# print scores reversed
print(tuple(reversed(scores)))

# print scores reversed
print(scores[::-1])

# print first score by index
print(scores[0])

# print first two scores
print(scores[0:2])

# print tuple
thistuple = ("apple",)
print(type(thistuple))

#NOT a tuple
thistuple = ("apple")
print(type(thistuple))
Comment

tuple python

from collections import namedtuple

Point = namedtuple('Point', 'x y')
p = Point(1, y=2)

p[0]
# 1
p.x
# 1
getattr(p, 'y')
# 2
p._fields  # Or: Point._fields
# ('x', 'y')
Comment

tuple python

# Change Value In Tuple :-

friends = ("Mido", "Lucifer", "Abdelrhman")

# Example => Wanna Change ( Abdelrhman ) To ( Aiiob );
# First We Need Transformation From Tuple To List ,
# We Need To Create Variable With Any Name 
# After This We Use list() Function

oneName = list(friends)

# After This We Need Change The Value ,

oneName[-1] = "Aiiob"

# After This We Need Transformation From List To Tuple ,
# We Use tuple() Function

friends = tuple(oneName)

# And We Done (:
Comment

tuplein python

a=(1,2,3,4)
print(a[-3])

Comment

tuple python

tuple = ("Facebook", "Instagram", "TikTok", "Twitter")
Comment

tuple python

tupel python
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

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 :: dicionario python 
Python :: bubble python 
Python :: how to make a list in python 
Python :: add list of dictionaries to pandas dataframe 
Python :: python filter numbers from list 
Python :: np.vectorize 
Python :: add two strings together 
Python :: convert radians to degrees python 
Python :: get lastest files from directory python 
Python :: python type hint list of specific values 
Python :: how to add a new element to a list in python 
Python :: merge dataframe using pandas 
Python :: dictionary comprehension python 
Python :: strip() 
Python :: get length of string python 
Python :: drop duplicates data frame pandas python 
Python :: PHP echo multi lines Using Nowdoc variable 
Python :: what is queryset in django 
Python :: python subprocess 
Python :: python warnings as error 
Python :: how to access a dictionary within a dictionary in python 
Python :: firebase functions python 
Python :: journalctl not showing all python prints 
Python :: read data from gooogle cloud storage 
Python :: hex string to hex number 
Python :: how to keep track of your sport running times in python 
Python :: put cropped image in original image name folder python 
Python :: python vs java 
Python :: python unittest setUpClass 
Python :: how to get a list of files in a folder in python with pathlib 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =