Kaizensk
308 FOLLOWERS
Welcome to Kaizensk, the platform where you get complete knowledge about cyber security, data science, information technology, computer hardware and software. We bring you anything and everything related to the tech world. Our main aim is to educate anyone and everyone who is passionate about learning.
Kaizensk
2y ago
While coding in python we may encounter several types of errors one of which is list index out of range python.
This error occurs while we are working on lists, also a similar type of error occurs when we are working with tuples.
1. Lists.
The list is one of four built-in collection data types in a python programming language.
Some of its features include, we can add or delete list items, we can sort list items and we use a list for multiple works based on our needs.
2. Index.
The index is a convention that is used by a python interpreter to store values in a fashion that can be easily remembe ..read more
Kaizensk
2y ago
A variable is an entity that keeps on changing according to its behavior.
We use different types of variables throughout any programming language, sometimes we have to initialize those variables based on what type of data it is going to accept, and sometimes it is auto initialized, these factors are dependent on the programming language.
But in this article, our main goal is to understand the types of variables in a python programming language.
Also, we will be focused only on types of variables used inside the class, object, or say method.
There are 3 types of variables in a python programmin ..read more
Kaizensk
2y ago
Python is the fastest-growing language in the world and it’s not just hype, it has some of the best features that any other programming language.
The built-in Python libraries provide some of the most useful and resources across various platforms.
If you ever got stuck somewhere then no issues, the python community is awesome always ready to push you beyond with all that said let’s see how to remove duplicates from a list in python.
List is one of the 4 built-in collection data types in python the other 3 are tuple, set and dictionary.
List acts like an array, it stores data in an ordered mann ..read more
Kaizensk
2y ago
On the road to become a successful developer we will come across many concepts some of are easy some of are difficult to grasp.
But some of are extremely easy and we might have not given a slightest effort to know what it is.
One of is what is function in python or what is method in python. Let’s simply begin with exactly function actually is.
A function is a block of code which is written once and only once and can be called every time to perform repetitive tasks.
Meaning you want to add two numbers and you wrote code for it, so what you will do is write those code in a manner in which it can ..read more
Kaizensk
2y ago
Definition:
This method simply removes the last inserted item from the dictionary, since it returns the item, we can print it directly or using any variable. The original dictionary gets changed.
Syntax:
X = dictionary.popitem()
This method takes no argument.
Working:
Copy Code Here.
dictionary = {1: ‘Student’,
‘Name’: ‘Waqar Khan’,
‘Age’: 23,
‘Male’: True,
‘Subjects’: ‘Computers’}
x = dictionary.popitem()
print(x)
print(dictionary)
Code:
A dictionary with some random values is being taken
popitem() method is being applied to the dictionary. And its returned value is printed inside x.
After ..read more
Kaizensk
2y ago
Definition:
Refer below image while reading definition.
This method returns the value of the specified key from the dictionary. Note that this method does not remove the item but it returns the copy of the item so the original item in the dictionary remains unchanged.
But this method also takes the 2nd argument which is optional. If the specified key is not present inside the dictionary, it will insert the item which is passed as argument and it will append it inside the dictionary changing the original dictionary and then returns that item.
Syntax:
X = dictionary.setdefault(‘key’, ‘value’)
K ..read more
Kaizensk
2y ago
Definition:
The update() method inserts the specified item into the existing dictionary. The item must be specified into curly braces meaning in dictionary format. This method changes the original dictionary.
Syntax:
Dictionary.update({key : value})
This method takes dictionary or iterable object as argument
Working:
Code In Text Form.
dictionary = {1: ‘Student’,
‘Name’: ‘Waqar Khan’,
‘Subjects’: ‘Computers’}
dictionary.update({‘University’:’MU’})
print(dictionary)
Code:
A dictionary with some random values is being taken
update() method is being applied and a single value dictionary is bei ..read more
Kaizensk
2y ago
Definition:
The values() method returns a view object. This view object contains the values of the dictionary in list format. Also, this view object is directly connected to the original dictionary so if any changes occur it will be reflected in the view object as well.
Syntax:
X dictionary.values()
This method takes no argument
Working:
Text format code is here, you can copy.
dictionary = {1: ‘Student’,
‘Name’: ‘Waqar Khan’,
‘Age’: 23,
‘Male’: True,
‘Subjects’: ‘Computers’}
x = dictionary.values()
print(x)
dictionary[‘Subjects’] = ‘Physics’
print(x)
Code:
A dictionary with some random valu ..read more
Kaizensk
2y ago
Definition:
This method simply removes the specified from the original dictionary, also pop method returns the value so we have to assign it to some variable. This method changes the original dictionary.
Syntax:
X = dictionary.pop(‘key_name’ , ‘Default’)
key_name = Your desired key
Default = Default value if no key is present (Optional)
This method takes a single argument.
Working:
Copy code below.
dictionary = {1: ‘Student’,
‘Name’: ‘Waqar Khan’,
‘Age’: 23,
‘Male’: True,
‘Subjects’: ‘Computers’}
x = dictionary.pop(‘Subjects’)
print(x)
print(dictionary)
Code:
A dictionary with some items is ..read more
Kaizensk
2y ago
Definition:
Similar to the items() method, this method also returns a view object, this time the view object contains the keys of the dictionary inside list. Also, this view object is directly connected to the original dictionary, meaning any changes in the original dictionary will be reflected here.
Syntax:
X = dictionary.keys()
This method takes no argument.
Working:
Code is here you can copy.
dictionary = {1: ‘Student’,
‘Name’: ‘Waqar Khan’,
‘Age’: 23,
‘Male’: True,
‘Subjects’: ‘Computers’}
x = dictionary.keys()
print(x)
dictionary[‘University’] = ‘MU’
print(x)
Code:
A dictionary with so ..read more