mirror of
https://github.com/Asabeneh/30-Days-Of-Python.git
synced 2026-06-12 21:01:48 +08:00
minor fixes
This commit is contained in:
parent
77e0f2db27
commit
8a72b58426
@ -17,4 +17,5 @@ print(type(1 + 3j)) # Complex
|
||||
print(type('Asabeneh')) # String
|
||||
print(type([1, 2, 3])) # List
|
||||
print(type({'name':'Asabeneh'})) # Dictionary
|
||||
print(type({9.8, 3.14, 2.7})) # Tuple
|
||||
print(type({9.8, 3.14, 2.7})) # Set
|
||||
print(type((9.8, 3.14, 2.7))) # Tuple
|
||||
|
||||
@ -373,8 +373,8 @@ print(challenge.index(sub_string, 9)) # error
|
||||
```py
|
||||
challenge = 'thirty days of python'
|
||||
sub_string = 'da'
|
||||
print(challenge.index(sub_string)) # 8
|
||||
print(challenge.index(sub_string, 9)) # error
|
||||
print(challenge.rindex(sub_string)) # 8
|
||||
print(challenge.rindex(sub_string, 9)) # error
|
||||
```
|
||||
|
||||
- isalnum(): Checks alphanumeric character
|
||||
|
||||
@ -58,7 +58,7 @@ fruits[0] = 'Avocado'
|
||||
print(fruits) # ['avocado', 'orange', 'mango', 'lemon']
|
||||
fruits[1] = 'apple'
|
||||
print(fruits) # ['avocado', 'apple', 'mango', 'lemon']
|
||||
last_index = len(fruits)
|
||||
last_index = len(fruits) - 1
|
||||
fruits[last_index] = 'lime'
|
||||
print(fruits) # ['avocado', 'apple', 'mango', 'lime']
|
||||
|
||||
@ -80,7 +80,7 @@ print(fruits)
|
||||
fruits = ['banana', 'orange', 'mango', 'lemon']
|
||||
fruits.insert(2, 'apple') # insert apple between orange and mango
|
||||
print(fruits) # ['banana', 'orange', 'apple', 'mango', 'lemon']
|
||||
fruits.list(3, 'lime') # ['banana', 'orange', 'apple', 'mango', 'lime','lemon',]
|
||||
fruits.insert(3, 'lime') # ['banana', 'orange', 'apple', 'mango', 'lime','lemon',]
|
||||
print(fruits)
|
||||
|
||||
# remove
|
||||
@ -92,10 +92,10 @@ print(fruits) # ['orange', 'mango']
|
||||
|
||||
# pop
|
||||
fruits = ['banana', 'orange', 'mango', 'lemon']
|
||||
fruits.remove()
|
||||
fruits.pop()
|
||||
print(fruits) # ['banana', 'orange', 'mango']
|
||||
|
||||
fruits.remove(0)
|
||||
fruits.pop(0)
|
||||
print(fruits) # ['orange', 'mango']
|
||||
|
||||
# del
|
||||
@ -161,10 +161,10 @@ print(ages.index(24))
|
||||
# Reverse
|
||||
fruits = ['banana', 'orange', 'mango', 'lemon']
|
||||
fruits.reverse()
|
||||
print(fruits.reverse())
|
||||
print(fruits)
|
||||
ages = [22, 19, 24, 25, 26, 24, 25, 24]
|
||||
ages.reverse()
|
||||
print(ages.reverse())
|
||||
print(ages)
|
||||
|
||||
# sort
|
||||
fruits = ['banana', 'orange', 'mango', 'lemon']
|
||||
|
||||
@ -61,7 +61,7 @@ person = {
|
||||
'age':250,
|
||||
'country':'Finland',
|
||||
'is_marred':True,
|
||||
'skills':['JavaScript', 'React', 'Node', 'MongoDB', 'Python']
|
||||
'skills':['JavaScript', 'React', 'Node', 'MongoDB', 'Python'],
|
||||
'address':{
|
||||
'street':'Space street',
|
||||
'zipcode':'02210'
|
||||
|
||||
@ -259,7 +259,7 @@ print(randint(5, 20)) # it returns a random integer number between [5, 20] inclu
|
||||
2. Modify the previous task. Declare a function named user_id_gen_by_user. It doesn’t take any parameters but it takes two inputs using input(). One of the inputs is the number of characters and the second input is the number of IDs which are supposed to be generated.
|
||||
|
||||
```py
|
||||
user_id_gen_by_user() # user input: 5 5
|
||||
print(user_id_gen_by_user()) # user input: 5 5
|
||||
#output:
|
||||
#kcsy2
|
||||
#SMFYb
|
||||
@ -267,7 +267,7 @@ user_id_gen_by_user() # user input: 5 5
|
||||
#ZXOYh
|
||||
#2Rgxf
|
||||
|
||||
user_id_gen_by_user() # 16 5
|
||||
print(user_id_gen_by_user()) # 16 5
|
||||
#1GCSgPLMaBAVQZ26
|
||||
#YD7eFwNQKNs7qXaT
|
||||
#ycArC5yrRupyG00S
|
||||
|
||||
Loading…
Reference in New Issue
Block a user