None
None
is an object which is a datatype of its own (NoneType).Used to define no value or nothing.
Code
PYTHON
Output
Function Without Return
Functions assigned to a variable, when function does not have a
return
statement, the variable will get the value None
Code
PYTHON
Output
Function That Returns Nothing
When a function returns no value, the default value will be
None
Example - 1
Code
PYTHON
Output
Example - 2
Code
PYTHON
Output
Example - 3
Code
PYTHON
Output
Tuple
- Holds an ordered sequence of items.
- Tuple is immutable object, where as list is a mutable object.
Code
PYTHON
Creating a Tuple
- Created by enclosing elements within (round) brackets.
- Each item is separated by a comma.
Code
PYTHON
Output
Tuple with a Single Item
Code
PYTHON
Output
Accessing Tuple Elements
Accessing Tuple elements is also similar to string and list accessing and slicing.
Code
PYTHON
Output
Tuples are Immutable
Tuples does not support modification.
Code
PYTHON
Output
Operations can be done on Tuples
- len()
- Iterating
- Slicing
- Extended Slicing
Converting to Tuple
tuple(sequence)
Takes a sequence and converts it into tuple.String to Tuple
Code
PYTHON
Output
List to Tuple
Code
PYTHON
Output
Sequence to Tuple
Code
PYTHON
Output
Membership Check
Check if given data element is part of a sequence or not.
Membership Operators
- in
- not in
Example - 1
Code
PYTHON
Output
Example - 2
Code
PYTHON
Output
List Membership
Code
PYTHON
Output
String Membership
Code
PYTHON
Output
Packing & Unpacking
Unpacking
Values of any sequence can be directly assigned to variables.
Number of variables in the left should match the length of sequence.
Code
PYTHON
Output
Errors in Unpacking
Code
PYTHON
Output
Code
PYTHON
Output
Tuple Packing
()
brackets are optional while creating tuples.In Tuple Packing, Values separated by commas will be packed into a tuple.
Code
PYTHON
Output
Code
PYTHON
Output
Code
PYTHON