Mehmet Nazlıay
2 min readJan 29, 2021

--

Hello Everyone,

I will continue ‘Introduction to Basic Python’ in this article.

Tuple

A tuple is a collection of objects like list but there is a important difference between list and tuple for us. List is mutable but tuple is unmutable, so you can not change any value in tuple.

We can create tuple as putting comma among different values like in the first line. Optionally we can use parentheses also.

In the fourh line we can see that tuple is immutable.

Dictionary

Dictionaries are indexed by keys which can be any immutable type. Strings or numbers can be key. A pair of braces creates an empty dictionary: {}. Dictionaries store data values in key:value pairs.

Above is a small example using a dictionary. We created value “dictionary1” and in the second line we can look value of “Black”. And in the third line we can change to “……” value of “Black”. Also, we can add new key like in the forth line. If we want to delete any key, we can use ‘del dictname[“keyname”]’. If we use ‘del dictname’, we remove value “dictname” completely like in the sixth line.

Function

As we already know, Python gives us many ready functions like print(), len(), but we can also create functions. As usual, we can start with small example.

Def marks the start of the function header. Sum is name of the function. a,b are argument through which we pass values to the function and they are optional. The colon (:) to mark the end of the function header. Return statement to return a value from the function and return is optional. We can use print(a+b) instead of second line. We can call the sum function like the third line and the line of third is 11.

When I talk about if statement and for loop, we will new example. This example very basic to understand many things.

If Statements

We should talk about conditions before if statement.

The if condition makes a decision based on whether the condition is true or not. If the condition is true, it outputs the desired expression. If the condition is false, it passes the desired expression.

The if-else condition adds an additional step to if statement. If the condition is false, under the else desired expression is outputed.

In the if-elif-else condition we can add additionals contions between if and else.

Thanks to your time, Have a nice day.

--

--