-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirstpythonfile.py
More file actions
160 lines (120 loc) · 6.4 KB
/
Copy pathfirstpythonfile.py
File metadata and controls
160 lines (120 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
print("Hi Python")
print('Hi Python')
#always start the print and end it with the same " or ' . Dont mix them up keep them the same.
print("----------------------")
print(" Learn Python ")
print("----------------------")
print("Hi \"Python\"") #the backslash before the double quotes tells python that the double quotes are in the content of the message
print('Hi \'Python\'') #the backslash before the double quotes tells python that the double quotes are in the content of the message
print('Hi "Python"') # as the message starts with single quotes, when using double quotes, the double quotes are seen as content
#print("Path: C:\users\Aron") #for eg here python always sees backslash as a special character
print("Path: C:\\users\\Aron") #Now the double backslash tells python that the backslash after the first one is in the content of the message
#How to create a gap between messages part 1
print("Message1")
print() #to create a space between messages,
print("Message2")
#How to create a gap between messages part 2
print("Message1\n") # the \n tells python to create a new line and moves the text that comes after it, onto the next line
print("Message2")
#How to create multiple gaps between messages
print("Message1\n\n\n") #this creates a 3 line gap
print("Message2")
print("Message1\tMessage2") #creates a tab between the two messages
print("Your learning path:\n\t-Python Basics\n\t-Data Engineering\n\t-AI")
#this is a long line of code, we can split it up to make the lines shorter, but spanning over multiple lines
print("""Your learning path:
\t-Python Basics
\t-Data Engineering
\t-AI""")
#you do this by using triple quotes, as we are using new lines in the code, we can get rid of all \n - multiple lines in output using one single print
x = 1
print(x)
x = 2
print(x)
y = x + 3
print(y) #x and y are both variables. x = 2 replaced x = 1 so y = 2 + 3
print("My name is Aron")
print("Aron is learning Python")
print("Aron wants to become a Python expert")
name = "Aron" #name is the variable and Aron is the value
print("My name is", name) #put the variable name with a , after to merge inputs
print(name, "is learning Python") #now the value of the variable name can be changed and all the values will also make the same change
print(name, "wants to become a Python expert") #whereas before the name variable was in double quotes so if the value changed, the output wouldn't
name = "Maria" #if the code is ran, the name would stay as Aron, and it would not change to Maria. This is because Aron is on a higher line(above it) and so is read first. Maria is not read until the output has already been given
language = "Python" #if you use same value over and over, store it in a variable to make the code easier to change
print("My name is", name)
print(name, "is learning", language)
print(name, "wants to become a", language, "expert")
#CHALLENGE - print the following three lines, add a variable to make it dynamic
#info@datawithbaraa.com
#support@datawithbaraa.com
#www.datawithbaraa.com
website = "datawithbaraa.com"
print("info@", website, "\nsupport@", website, "\nwww.", website)
input("Enter your name:") #can't do anything with this, so we store it in a variable instead
name = input("Enter your name:") #the value the user enters is the value of the variable name
print("You are", name)
name = input("Enter your name:") #variable name is a dynamic value as the value entered by user varies
country = "Germany" #variable country is a hard coded value as it doesn't change
print(name, "comes from", country)
#Putting everything together
x = "A" #hard coded value as it is given and cannot be changed
print(x)
#Ask for a value
y = input("Enter value:") #dynamic value as the answer can vary
print(y)
#Data types
#Adding numbers
# 2 + 3 -> 5 #integer + integer
# "2" + "3" -> 23 #string + string (no mathetmatical operation)
a = 10 #int - whole number without decimals
b = 3.15 #float - number with decimal points
c = "Hello" #str
d = '1234' #str
f = True #bool boolean - can either be true or false
g = False #bool boolean - can either be true or false
h = None #NoneType - no value, nothing or unknown - used to show absence of data
i = "" #str - blank value with no characters inside, its NOT the same as None, we call this a blank
j = " " #str - empty space " " is a string value with one or more spaces
text = "hi"
number = 10
type(text) #type() is a built-in function and it returns the data type of a value so you know what kind of object it is
type(number) #type doesn't print anything in the output
#to see what kind of object the value is you do as in the format below (a function inside another function)
print(type(text)) #the output will be <class 'str'>
print(type(number)) #the output will be <class 'int'>
#len() is a built-in function that gives the total count of items inside a value, helping measure length
print(len(text)) #output will be 2
#print(len(number)) #output is Typeerror since object type 'int' has no length len()
#not all functions will work for all data types
print(text.upper()) #makes all of the values uppercase
#print(number.upper()) - 'int' object has no attribute 'upper'
print(number.bit_length()) #output: 4 this means that 4 bits are needed to store the value 10
#bit_length() method of <class int> returns the length of a number in binary
#print(text.bit_length()) output: atrribute error as 'str' object has no attribute 'bit_length'
# CHALLENGE
#create 5 variables - each with a different data type
#1 - your age, 2 - Your height with decimals, 3 - Your name, 4 - are you a student, 5 - something with no value yet
#then print the values, data types and lengths of all variables
age = 19
height = 177.5
name = 'Aron'
student = True
unknown = None
print(age)
print(type(age))
print(age.bit_length())
print(height)
print(type(height))
#you cannot directly find a length for height (a float) as it does not have a length in python
#you could convert it to a string by using print(len(str(height))) output: length is 5
print(name)
print(type(name))
print(len(name))
print(student)
print(type(student))
print(student.bit_length())
print(unknown)
print(type(unknown))
#you cannot directly find a length for unknown (a None) because it doesn't have a length in python
#you could convert it to a string by using print(len(str(unknown))) output: length is 4