# What does *tuple and **dict mean in Python

If you want to learn tuples and dict in Python programming.

## What does mean by *tuple?

Tuple – The tuple contains the group of elements which can be the same or different types:-

• A tuple is occupied less memory wrt the list.
• Tuples are represented using parentheses ( ).

Ex:- a = (21, 23, 27, 30, ‘CodeSpeedy’)

1. Creating Empty Tuple

If you want to create an empty tuple using below this syntax.

Syntax:- tuple_name = ( )

Ex:- a = ( )

2.Creating Tuple

If you Want to  create tuple by using an elements separated by  the , (commas) inside the parentheses you can see below the example .

⇒With one Element

b = (17)    ⇐  It will become integer

c  = (25, )

⇒With Multiple Elements

d = (11, 17, 19, 27)

e = (11, 17, 19, 27,’CodeSpeedy’)

f = 11, 23, -55, 21.7, ‘CodeSpeedy’

⇒Index

The index is represented by the using position number of a tuple’s element. The index is starts from 0 onwards and is used inside this braces [ ].

Ex:- a = (11, 23, -55, 21.7, ‘CodeSpeedy’)

⇒Accessing Tuple’s Element

a = (11, 23, -55, 21.7, ‘CodeSpeedy’)

print(a)

print(a)

print(a)

print(a)

print(a)

Code:-

```# Tuple
# Creating Empty Tuple
a = ()   #integer

# Creating Tuple with one element
b = (11)
c = (25,)

# Creating Tuple with Multiple element
d = (11, 23, 35, 47)
e = (11, 23, -55, 21.7, 'CodeSpeedy')
f = 11, 23, -55, 21.7, 'CodeSpeedy'		# e and f are same

print()
# Access using index:-
print("Accessing Tuple d:")
print("d =", d)
print("d =", d)
print("d =", d)
print("d =", d)
print()

print("Accessing Tuple e:")
print("e =", e)
print("e =", e)
print("e =", e)
print("e =", e)
print("e =", e)
print()

print("Accessing Tuple f:")
print("f =", f)
print("f =", f)
print("f =", f)
print("f =", f)
print("f =", f)

```

OutPut:-

```Accessing Tuple d:
d = 11
d = 23
d = 35
d = 47

Accessing Tuple e:
e = 11
e = 23
e = -55
e = 21.7
e = CodeSpeedy

Accessing Tuple f:
f = 11
f = 23
f = -55
f = 21.7
f = CodeSpeedy
```

## What does mean by *dict?

*dict( ) Function:-

This function creates a new dictionary. This can be also used in type casting to convert iterable to dict.

Syntax:– dict(**keywors_arguments)

Code:-

```# Dictionary Comprehension
lst = [(103, "Code"), (102, "Speedy")]
dict = {s:v for s,v in lst}
print(dict)
```

OutPut:-

```{103: 'Code', 102: 'Speedy'}
```

.With and without Dict.

```# Without Dict Comprehension
dict = {}
for n in range(13):
dict[n]=n*3
print(dict)

# With DIct Comprehension
dictX = {n:n*3 for n in range(13)}
print(dictX)
```

OutPut:-

```{0: 0, 1: 3, 2: 6, 3: 9, 4: 12, 5: 15, 6: 18, 7: 21, 8: 24, 9: 27, 10: 30, 11: 33, 12: 36}
{0: 0, 1: 3, 2: 6, 3: 9, 4: 12, 5: 15, 6: 18, 7: 21, 8: 24, 9: 27, 10: 30, 11: 33, 12: 36}

```