In this series we will together learn the fundamentals of Python,
Enough for us to be able to realize interesting projects.
Together we will build an ever improving unit converter
So what is Python?
Python is a general purpose language, meaning it can be used for just about any project you fancy.
Python is an interpreted language — the code you write works on any OS
This interpretation costs time and thus makes Python slightly slower than compiled languages such as C or C++.
Yet biggest advantage of Python is its speed of development
You can create applications very fast
Should you still need this extra edge in speed you can still convert certain sections of your app into another language and then integrate these to your python code
Plus points for Python:
– Easy to learn = Good foundation for future languages
– Loads of libraries that will support our future endeavors
– Rapid development
How to use Python
– Download from python.org and install
– You can Python’s IDLE
– You can use editors such as notepad++ or Visual Studio Code, or Atom
– You can use an IDE such as Pycharm, Visual Studio, Eclipse
– Pick what you like, and quickly find out how your dev tool works with python.
You’ll find tons of free tutorials online
Let start small
Let us print our first conversion, namely from km to miles
We have 15 km. How many miles would that be
Conversion factor from km to miles is 0.621271
So 15 * 0.621271 would give us this distance in miles
So print(15*0.621271) would make python produce the distance in miles
You can easily replace the 15 with any other distance and Python would then print the miles for the new distance
What would be helpful is to know what these numbers stand for. That is what comments are here for.
Ie # km = 15 is a comment. This line does not get executed by Python
# version 0
# km = 15
# conversion = 0.621371
print(15*0.621371)
In version 1 we want to convert these 16 km to multiple other units:
# version 1
# km = 15
# conversion to miles = 0.621371
# conversion to yards = 1093.61
# conversion to feet = 3280.84
# conversion to nautical miles = 0.539957
print(15 * 0.621371) # km to miles conversion
print(15 * 1093.61) # km to yards conversion
print(15 * 3280.84) # km to feet conversion
print(15 * 0.539957) # km to nautical miles conversion
#python #beginner #tutorial