Python Fundamental
Python is a user-friendly programming language known for its simplicity and adaptability. It is widely utilised to develop software applications and perform various tasks, including web development, data analysis, and automation. Due to its ease of use and versatility, Python has gained significant popularity among programmers.
append(x)
Add an item to the end of the list. Equivalent to a[len(a):] = [x].
fruits
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
>>> fruits.append('grape')
fruits
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']
pop([i])
Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list.
fruits
['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']
>>> fruits.pop()
'pear'
.reverse()
Reverse the elements of the list in place.
A set is an unordered, unchangeable*, and unindexed collection.
The duplicate value will be ignored. But we can add or remove
>>>thisset = {"apple", "banana", "cherry", "apple"}
print(thisset)
>>>{'apple', 'banana', 'cherry'}
Methods and Description :
add() : Adds an element to the set
clear() : Removes all the elements from the set
copy() : Returns a copy of the set
pop() : Removes an element from the set
remove() :Removes the specified element
update() : Update the set with the union of this set and others
Dictionary
Dictionaries are used to store data values in key: value pairs.
A dictionary is a collection which is ordered*, changeable and does not allow duplicates.
Python Fundamental- 01.
Happy data science learning with basic Python. We can start basic Python with print function (), variable, Data Types & comments.
Definition and Usage: The print() function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen. Print function as like as printer.
After completing any online registration, after using ATM booth with debit card we get a successful message & error message which we can consider the Real life example of print function ().
print(‘Your registration has been done successfully.’)
Output: Your registration has been done successfully.
A variable name must start with a letter or the underscore character
A variable name cannot start with a number
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
Variable names are case-sensitive (age, Age and AGE are three different variables)
Basic Types: (Integer, Float, Complex, Boolean, and string)
Container Types: (List, Tuples, Sets and Dictionary)
User-Defined Types- Class
Python Comments: We can lock each line code with a separate Hash #, Which called multi line comment. We can keep any sentence or code in the comments.
If we don't want to run any code, then we write the #(Hash) and any code will not run after or under the hash # symbol.
Creating a Comment:
# This is a Comment
print("Bismillah.")
output: Bismillah.
#Multi Line Comments with 3times double quotation """ in the first line and the last line.
"""
We can lock multi line code
print("SMART work first & Hard work Must.")
Output: SMART work first & Hard work Must.
Python Casting: Casting use to specify the data type of a variable
x = str(4) # x will be '4'
y = int(4) # x will be 4
z = float(4) # x will be 4.0
print(x, y, z)
Output: 4 4 4.0
Find the data type of variable:-
X = 5
Y = 5.0
Z = "5"
_2M = True
print(type(X))
print(type(Y))
print(type(Z))
print(type(_2M))
Output|:
<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
Some more variable :
Single or Double Quotes.
Case-Sensitive.
Python Variables - Assign Multiple Values:
Many Values to Multiple Variables.
One Value to Multiple Variables.
Unpack a Collection