Search This Blog

Variables - Python

Variables. Variables are only names or you can say boxes having value in them, for example X = 1, where X is a variable having the value 1, X = 10, X is a variable having value 10, another thing variables do not change but their value can change, for example X = 1+2 will change the value of X to 3 and X will become X = 3.

So here we will learn how to work with variables in miss Python programming.

How to make a variable and assign them value, for example I want to make X with value 10, then I will do the following work in python shell.(python shell, where we type commands and get output instantly after typing commands)

command is X a space then equal to symbol then a space and the value.

>>>x = 10 <-- press enter after typing this, and It will save 10 into variable X. Then you can use X anywhere in maths programming.

Now our X has the value of 10 then we can use the X by following ways

>>>X + 5 <-- Our input (input is our/user instruction given to the computer), will add X into 5, actually will do nothing with X but with the value of X.

15 <-- output

Lets use power(exponent) thing here, X exponent 3 give us output of 10 exponent 3, because the value of our X was 10.

>>> X*3

30

Remember that our variables are case sensitive, I mean capital X and small x are different and can be used at a same time in same program.

>>>x = 5

>>>x + X <-- it will do addition with the stored values of small x which was 5 and with capital X which was 10.

15

We can store more than one variable same time. >>>y = 50

>>>y + x

55

We can also take the values of variables from the user using input function,

>>>a =input("Enter the value of a: ")

Enter the value of a:

>>>b =input("type the value of b: ")

type the value of b:

We can also get value of variable from user without any message

>>>c =input()

<-- this empty space as output will come, it is because we did not include any message like Enter your number, Type the value of c etc. but it will also save value of c even without message.

>>>c =input("Type the value of c: ")

Type the value of c:

Practice makes a man perfect :) try more different variables play with variables in your python now for your practice.

Post a Comment

Popular Posts

Want to show your blog posts summary with Tweets? This feature is available for anyone by Twitter. It is called Twitter Cards. You need to configure your blog/site according to Twitter guide in order to display your links summary in tweets. WordPress.com blogs already have this support but for WordPress.Org blogs you need some Twitter Cards plugin or edit your template.

Here I am going to tell you how can you make your blogspot/blogger blog posts to display summaries of your blog links in Tweets.
It is very easy, just copy paste this code into your blogspot blog template before </head> tag. You need to edit only one thing in this code, that is Twitter username. Put your Twitter username and use the code given below.

Requirements: Your phone's USB drivers should be installedAndroid SDK Download it as zip and extract/place in C drive.USB Debugging on phone enabled (Settings\Applications\Development\USB debugging)You’ll need to have superuser permissions installed on your phone. This can normally be obtained by rooting your device then installing a custom ROMHow To Remove the 100 SMS Per Hour Limit
1. Open the command prompt 2. Copy and paste the following command into command prompt and press Enter key. This will navigate to your Android SDK folder in C drive and output will be C:\Android\platform-tools>
cd C:\Android\platform-tools
3. Once you’ve navigated there, enter the following commands, one per line. Do not enter anything in red, this is for informational purposes, and what will display on your command prompt as output. C:\Android\platform-tools> adb shell# sqlite3 /data/data/com.android.providers.settings/databases/settings.db
sqlite3 /data/data/com.android.providers.settings/databas…

Control Center: Turn on or off Airplane mode, Wi-Fi, Bluetooth, and Do Not Disturb. Lock your screen’s orientation or adjust its brightness. Play, pause, or skip a song. Connect to AirPlay-enabled devices. And quickly access your flashlight, timer, calculator, and camera.

New Notification Center: New notification center features give you a convenient summary of, well, today. One glance at your iPhone and you’ll know if it’s a certain someone’s birthday, if you’ll need an umbrella, or if traffic will slow down your commute. You’ll even get a heads-up on tomorrow. You can access Notification Center from any screen, including the Lock screen. Just swipe down.

New Multitasking: Press the Home button twice to see preview screens of the apps you have open. To quit an app, just swipe it up and out of preview.