Skip to content

Commit e0ee7cb

Browse files
committedJul 20, 2022
Python Commit
0 parents  commit e0ee7cb

File tree

402 files changed

+16200
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

402 files changed

+16200
-0
lines changed
 

‎Arrays.py

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Python Arrays
2+
# *Note: Python does not have built-in support for Arrays, but Python Lists can be used instead.
3+
4+
# Arrays
5+
# *Note: This page shows you how to use LISTS as ARRAYS, however, to work with arrays in Python you will have to import a library, like the NumPy library.
6+
7+
# Arrays are used to store multiple values in one single variable:
8+
9+
# Example
10+
# Create an array containing car names:
11+
12+
cars = ["Ford", "Volvo", "BMW"]
13+
14+
# What is an Array?
15+
# An array is a special variable, which can hold more than one value at a time.
16+
17+
# If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this:
18+
19+
car1 = "Ford"
20+
car2 = "Volvo"
21+
car3 = "BMW"
22+
23+
# However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300?
24+
25+
# The solution is an array!
26+
27+
# An array can hold many values under a single name, and you can access the values by referring to an index number.
28+
29+
# Access the Elements of an Array
30+
# You refer to an array element by referring to the index number.
31+
32+
# Example
33+
# Get the value of the first array item:
34+
35+
x = cars[0]
36+
# Example
37+
# Modify the value of the first array item:
38+
39+
cars[0] = "Toyota"
40+
41+
# The Length of an Array
42+
# Use the len() method to return the length of an array (the number of elements in an array).
43+
44+
# Example
45+
# Return the number of elements in the cars array:
46+
47+
x = len(cars)
48+
49+
# *Note: The length of an array is always one more than the highest array index.
50+
51+
# Looping Array Elements
52+
# You can use the for in loop to loop through all the elements of an array.
53+
54+
# Example
55+
# Print each item in the cars array:
56+
57+
for x in cars:
58+
print(x)
59+
60+
# Adding Array Elements
61+
# You can use the append() method to add an element to an array.
62+
63+
# Example
64+
# Add one more element to the cars array:
65+
66+
cars.append("Honda")
67+
68+
# Removing Array Elements
69+
# You can use the pop() method to remove an element from the array.
70+
71+
# Example
72+
# Delete the second element of the cars array:
73+
74+
cars.pop(1)
75+
76+
# You can also use the remove() method to remove an element from the array.
77+
78+
# Example
79+
# Delete the element that has the value "Volvo":
80+
81+
cars.remove("Volvo")
82+
83+
# *Note: The list's remove() method only removes the first occurrence of the specified value.
84+
85+
# Array Methods
86+
# Python has a set of built-in methods that you can use on lists/arrays.
87+
88+
# Method Description
89+
90+
# append() Adds an element at the end of the list
91+
# clear() Removes all the elements from the list
92+
# copy() Returns a copy of the list
93+
# count() Returns the number of elements with the specified value
94+
# extend() Add the elements of a list (or any iterable), to the end of the current list
95+
# index() Returns the index of the first element with the specified value
96+
# insert() Adds an element at the specified position
97+
# pop() Removes the element at the specified position
98+
# remove() Removes the first item with the specified value
99+
# reverse() Reverses the order of the list
100+
# sort() Sorts the list
101+
102+
# *Note: Methods of Arrays & Lists Are Exactly Same
103+
# *Note: Python does not have built-in support for Arrays, but Python Lists can be used instead.
104+

‎Basic.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
if 5 > 2:
2+
print("5 is greater then 2")
3+
if 5 > 2:
4+
print("5 is greater then 2")
5+
6+
# Variable declaration
7+
a = 5 # a is of type int
8+
y = "Hello, world!" # y is of type str
9+
10+
# Casting -> If you want to specify the data type of a variable, this can be done with casting
11+
12+
x = str(3) # x will be '3'
13+
y = int(3) # y will be 3
14+
z = float(3) # z will be 3.0
15+
16+
print(a)
17+
print(y)
18+
19+
# type() -> You can get the data type of a variable with the type() function.
20+
21+
print(type(x))
22+
print(type(y))
23+
print(type(z))
24+
25+
q = "Rishi" # Double-Quote
26+
Q = 'Rishi' # single-Quote
27+
28+
# Also Pythom variables are case Sensitive, Mena one cannot overcome 'q' with 'Q'
29+
30+
# This is a comment
31+
32+
"""
33+
This is a Multiline comment
34+
"""

0 commit comments

Comments
 (0)
Please sign in to comment.