Skip to main content

What is Python and how do you get started?

what is python

Let’s start from the beginning: what is Python and why should you learn it?

Python is one of the world’s most popular programming languages. It powers a huge number of extremely influential apps and websites, including Instagram, Google, Spotify, and Netflix. Python is also commonly used in data science and machine learning, which makes it a very “future-proof” language and one that is likely to stay in-demand for a long time.

Python powers a huge number of extremely influential apps and websites, including Instagram, Google, Spotify, and Netflix.

Despite its clear power and flexibility though, Python is also one of the most beginner-friendly programming languages you’re likely to come across. Python serves as a fantastic “gateway drug” into the world of coding, and offers a gentle introduction to higher-level concepts such as object-oriented programming.

Python is also one of the most beginner-friendly programming languages.

Development on Python began in the 1980s, led by Guido van Rossum at Centrum Wiskunde & Informatica in the Netherlands. This was very much Guido’s brainchild, and he even dubbed himself the language’s “Benevolent Dictator for Life” (BDFL) though he would step down from this role in 2018, passing responsibility on to the Python Steering Council instead.

Also read: How to become a data analyst and prepare for the algorithm-driven future

What is Python in programming terms? Python was conceived as an alternative to the ABC language. It is an interpreted, dynamically typed, garbage-collected language that supports numerous paradigms (object-oriented, procedural, functional).

If you’re just starting out, you don’t need to worry about any of this. Just know that Python is relatively simple to learn, but also highly in-demand and very powerful. Let’s take a look at how to get started with it and how to build your first, very simple, app.

How to get started with Python

First things first, you will need to download some software to use to start programming in Python.

If you’re on a desktop computer, that means two things:

  • A Python interpreter
  • A Python IDE

What is a Python interpreter? This is the software that reads the Python code and runs it. Installing an interpreter is like teaching your computer how to speak a foreign language.

python coding

The IDE meanwhile, is the “Integrated Development Environment.” This is the program that you will use to actually type your Python code into. You can save and open files this way, and all on the interpreter when you want to run it. This is your interface for Python development.

When installing an interpreter, you need to decide whether you’re going to choose Python 2 or Python 3. Each version has pros and cons, but Python 2 is no longer officially supported, making Python 3 the future-proof choice.

(If you were wondering “what is Python not so good for” one answer is that it is fragmented in this manner, which can present a little bit of confusion getting started!)

Download the latest Python interpreter here:

Note that you may already have a Python interpreter installed, especially if you are running MacOS or Linux.

When it comes to the IDE, there are a number of good options to choose from. Some of these are free, others will cost money but offer advanced features. Some good options include:

PyCharm is free and is among the most popular options for Python development. It is the tool I recommend for most users. That said, it can be a little complex to set up, so be sure to follow the official documentation here.

On mobile, things are simpler because the IDE and interpreter are built into a single app. This is a great way for beginners to get started.

To start coding on mobile, you’ll find a single app and download it. Two good examples for learning the ropes are:

There are other versions available with a range of payment models. Both these are good choices for getting started free though.

Once you have any of these things installed, you’re ready to write your first Python program!

Python 3: Hello World

It is tradition when learning any new programming language, to start by writing a piece of code that simply writes “Hello World” to the screen. To that end, you will need to use the following code:

Print(“Hello World”)

Now hit “Play” and you should see the text appear on the screen.

Python programming

Side note: If you were using Python 2, you wouldn’t need the brackets.

Let’s move quickly onto the next lesson: what is a variable in Python?

A variable is like a container that can be used to represent a number or a piece of text. We define this in the code by simply writing a word and then giving it a value.

For example, you could say:

MyVariable = “Hi there!”

Print(MyVariable)

You will see the message “Hi there!” appear on the screen. Notice that you don’t need the quotation marks to print a variable, quotation marks are interpreted literally.

A group of letters like this is known in programming as a “string.” This is one type of variable, but there are many others. Another type of variable is an integer. This is a variable that represents a whole number.

So we could also say:

MyVariable = 3

Print(MyVariable)

Which would print the number 3 onto the screen!

Some other languages would require you to specifically state what type of variable you wanted to use (String MyVariable = “Hello!”), but in Python, the interpreter figures that out from context. Part of the reason this is possible is that Python uses a smaller number of variable types as compared with, say, Java. There are no “Booleans” in Python for example.

While we won’t need to deal with other data types right now, you will eventually encounter the following variables in Python programming:

  • Numbers
    • Integers
    • Floats
    • Longs
    • Complexes
  • Strings
  • Lists
  • Tuples
  • Dictionaries

Manipulating data in Python

Why would you ever want to use a variable? Because it makes your code dynamic. It means that you can alter the way your program behaves depending on the action of the user, and depending on various other factors.

Try running this code and see what happens:

MyVariable1 = 2

MyVariable2 = 20

Print(MyVariable1 * MyVariable2)

Here’s a clue: in computer-talk, the * symbol represents multiplication.

You can also combine strings in interesting ways:

FirstName = “Bill”

LastName = “Gates”

FullName = FirstName + “  “ + LastName

print(FullName)

Your first Python 3 app!

So now we’ve answered the question “what is Python” and we’ve had a go at writing some basic code.

What about making something that a person might actually be able to use and have fun with?

Also read: Kotlin vs Java for Android: Key differences

To do this, we’re going to need to let the user interact with the program. That means we need to handle input.

Try this:

UserName = input(“Please enter your name: ”)

Print(“Hello “ + UserName)

You can probably figure out what is going on here! When you use the command “input,” Python will prompt the user with the text in the brackets, and then wait for the response. That string will then be referred to as UserName.

Note: Python 2 uses raw_input instead of input.

Run Python on Android

Now we have inputs, the ability to talk to the user, and even some basic math. How about we put this together in a fun little app? This one will tell you how long you have until you are 100 years old!

UserAge = input("How old are you? ")

YearsTo100 = 100 - int(UserAge)

print("In ", YearsTo100, "years, you'll be a hundred!!")

print("That is ", int(UserAge) * 360, " days! Or ", (int(UserAge) * 360) * 24, " hours. ")

Conditional statements

Android Studio development

There is one last trick that I want to share with you before we go: using conditional statements.

A conditional statement is a command that only runs under certain conditions. This usually means checking the value of a variable first.

To use a conditional statement in Python, you use the “If” statement, followed by an indentation.

For example:

UserName = input(“Please enter your name:”)

print(“Hello “ + UserName)

if UserName == “Adam”:

                print(“Admin mode enabled”) 

print(“What would you like me to do now?”)

In this program, the indented code will only run if the UserName given is Adam. Note that when checking a value as opposed to assigning one, we use two = signs rather than one.

Here then, the user will be asked what they want to do next whoever they are – but only I will be granted admin status. Or other people called Adam.

We’re just scratching the surface of Python can do

Using these basic commands and lessons, you can actually do an awful lot already. You could make a quiz, a calculator, a simple database, and more! To really flex the full power of Python though, you’ll need to understand concepts such as functions, modules, and more. To that end, we recommend checking out our guide to the best online Python courses. 

That said, if you’re a true beginner and looking for a great course that’s easy to get started with, we highly recommend Coding with Python: Training for Aspiring Developers, which you can nab for just $49.99, which is an absolute steal as the course is valued around $700.

$49 .99
Coding with Python: Training for Aspiring Developers Bundle
Save $641 .01
Buy it Now
Coding with Python: Training for Aspiring Developers Bundle Buy it Now
Save $641 .01 $49 .99


source https://www.androidauthority.com/what-is-python-1120588/

Comments

Popular posts from this blog

5 tips to Voice Speech Recognition in Android Marshmallow

Android Marshmallow landed on our Android devices. The opportunity for us to offer a small compilation of tricks to try immediately. The latest version of the Google OS starts (very gently, unhurriedly) to be offered on other devices as Nexus. You will find on Android TM, in the coming weeks, a compilation of the best tips for Android 6.0 Marshmallow. It starts slowly with a video featuring the 10 essential tips & tricks of this new version of the little green robot OS. To continue, we offer a selection of five "tricks" on the management of the battery on Android 6.0 Marshmallow. To enjoy longer your newly updated mobile. Follow the guide. then continue with 5 tips to tame the super-assistant Google Now on Tap. Here you will find 5 "tips" to manage in the best way your applications. We then discuss the quick tips to navigate more easily on this version of the Google OS. We enchanters with features focused on safety and the protection of personal data. We co...

Energy Android TV Play turns your TV into a Smart TV

ENERGY SISTEM Android Energy TV Play, you have a smart TV with Android operating system allows you to convert any traditional TV has announced the launch of a new product. Energy Android TV Play can be connected to the TV to enjoy f the size of a flash drive, a smart phone, a tablet and a computer unconsolidated is a lightweight device. System 1.6 GHz, DDR3 1GB of RAM and a dual-core processor can be expanded using external USB devices, which is the internal memory of 8 GB. It also integrates WiFi and a USB port for connecting external devices. One of its outstanding features, it is easily connected to the TV screen by screen cast application to display the contents of any terminal, making any phone or tablet is synchronized with iOS or Android. All ENERGY SISTEM products one click In addition, through streaming media service applications, images, video or other multimedia content, and game play is the ability to share. With integrated WiFi, the device you want from t...

How to run Python apps on any platform

Credit: Adam Sinicki / Android Authority Want to know how to run Python? It sounds simple, but it can actually be tricky to figure this out. In this post, we’ll discuss how to test your Python code, as well as how to run Python in other contexts: online for example, or as a packaged app. Sometimes, the thing holding you back from learning to code can be extremely simple. I remember wanting to learn to program when I was younger – or learning to take what I’d learned from BASIC on the ZX Spectrum and apply that to a modern environment. My problem? I didn’t know “where” to program. Once I understood C# or Java, where would I enter the code and how would I run it? And whenever I asked someone, they would look at me blankly. What kind of a question is that? Thing is, I had never needed an IDE or an interpreter before. Machines like the ZX Spectrum and Tatung Einstein (any other Einstein users out there?) simply booted up with a prompt to code into! Many people have a similar iss...