I always listen to people that they have learn to code using Python and it makes me wonders for all this time so today I’ll be showing you how to code using Python, just basic nothing advance. If you’re a hardcore programmers, Python is easy and simple in fact it is one of the easier ones to learn. Python has different version such as IronPython, IPython, CPython, PyPy, Jython, Canopy and more. In this post, I’ll be using the CPython. Below is the list that I’ve installed:
- Visual Studio Ultimate 2013
- Python Tools for Visual Studio
- Python 3.4 interpreter
- Open up the Microsoft Visual Studio.
- Click New Project, select Python and select Python Application as shown below.
- Name, HelloWorld and Click OK.
- And you’ll see blank page as shown below:
And there you can write the code, example:
print('Hello World') name = input("What is your name? ") print("\nYour name is: " + name) print(name.lower()) print(name.upper()) print(name.swapcase()) To run the program, Click on the Start on the menu bar. Output:
Another example on numbers:
no1 = 5 no2 = 2
add = no1 + no2 #addition sub = no1 - no2 #subtration mul = no1 * no2 #multiplication div = no1 / no2 #division exp = no1 ** no2 #exponent mod = no1 % no2 #modulo
print("Numbers: %d , %d" % (no1, no2)) print("Addition: %d" % no1 + " + %d" % no2 + "= %d" % add) print("Subtration: %d" % no1 + " - %d" % no2 + "= %d" % sub) print("Multiplication: %d" % no1 + " * %d" % no2 + "= %d" % mul) print("Division: %d" % no1 + " / %d" % no2 + "= %d" % div) print("Exponent: %d" % no1 + " ** %d" % no2 + "= %d" % exp) print("Modulo: %d" % no1 + " %% %d" % no2 + "= %d" % mod) Have you notice that Python has a different ways of displaying the numbers. It uses the placeholder just like C/C++. Output:
That’s it for basic programming using Python. And… you’ll probably ask why should we learn Python when there are tons of other languages that you could use and Python seems like it is going to be faded away anytime soon (that’s what I thought at the beginning). Well it’s not and it is widely use, it is