(Sponsors) Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!
Getting started with python
Updated on Nov 18, 2019
What is Python? #
Python is a general-purpose programming language created by Guido Van Rossum. Python is most praised for its elegant syntax and readable code, if you are just beginning your programming career Python suits you best. With Python you can do everything from GUI development, Web application, System administration tasks, Financial calculation, Data Analysis, Visualization and list goes on.
Python is an interpreted language #
Yes, Python is interpreted language, when you run python program an interpreter will parse python program line by line basis, as compared to compiled languages like C or C++, where compiler first compiles the program and then start running.
Now you may ask, so what's the difference??
The difference is that interpreted languages are a little bit slow as compared to compiled languages. Yes, you will definitely get some performance benefits if you write your code in compiled languages like C or C++.
But writing codes in such languages is a daunting task for a beginner. Also in such languages, you need to write even most basic functions like calculate the length of the array, split the string etc. For more advanced tasks sometimes you need to create your own data structures to encapsulate data in the program. So in C/C++ before you actually start solving your business problem you need to take care of all minor details. This is where Python comes. In Python, you don't need to define any data structure, no need to define small utility functions because Python has everything to get you started.
Moreover, Python has hundreds of libraries available at https://pypi.python.org/ which you can use in your project without reinventing the wheel.
Python is Dynamically Typed #
Python doesn't require you to define variable data type ahead of time. Python automatically infers the data type of the variable based on the type of value it contains.
myvar = "Hello Python"
The above line of code assigns string
"Hello Python" to the variable
myvar, so the type of
myvar is string.
Note that unlike languages like C, C++ and Java, in Python you do not need to end a statement with a semicolon (
Suppose, a little bit later in the program we assign variable
myvar a value of
myvar = 1
myvar variable is of type
Python is strongly typed #
1 + "2"
Here, before addition (
+) is carried out,
1 will be converted to a string and concatenated to
"2", which results in
'12', which is a string. However, In Python, such automatic conversions are not allowed, so
1 + "2"
will produce an error.
Try it out:
# run this code to see the error 1 + "2"
Write less code and do more #
Programs written in Python are usually 1/3 or 1/5 of the Java code. It means we can write less code in Python to achieve the same thing as in Java.
To read a file in Python you only need 2 lines of code:
with open("myfile.txt") as f: print(f.read())
Try it out:
# these two lines create a file "myfile.txt" with data "Learning Python" with open("myfile.txt", "w") as f: f.write("Learning Python") # these two lines read data from myfile.txt with open("myfile.txt") as f: print(f.read())
Don't pay much attention to the commands being used to read and write the file. We will learn all that in the upcoming posts.
Who uses Python #
Python is used by many large organizations like Google, NASA, Quora, HortonWorks and many others.
Okay, what I can start building in Python?
Pretty much anything you want. For e.g:
- GUI applications.
- Web apps.
- Scrape data from websites.
- Analyse Data.
- System administration utilities.
- Game Development.
- Data Science
and many more ...
In the next post, we will learn how to install Python.
Other Tutorials (Sponsors)
This site generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!