Posts

Showing posts with the label python

How to check the installed python version?

Image
Check the python version your machine currently using by typing the following commands in your terminal. bash- 5.1 $ python -- version Python 3.9 . 12 Check the python version via the python script. #import sys module in python sys module contain tuple of strings containing all the built in modules and constants import sys print(sys.version) #get the python version Check which version you are using if you have multiple python versions installed. You can check what version of python you are using by typing python in the terminal. bash- 5.1 $ python Python 3.9 . 12 (main, Apr 5 2022 , 06 : 56 : 58 ) [GCC 7.5 . 0 ] :: Anaconda, Inc. on linux Type "help" , "copyright" , "credits" or "license" for more information. >>> Check the python interpreter location using the terminal. To check the python interpreter location type command which python command.  (base) bash- 5.1 $ which pyt...

Graphing with Python using Matplotlib

Image
 Introduction Matplotlib is a graphing and plotting library that can be useful for creating different types of graphs and plots. Such as line charts, pie charts, scatter plots and 3D plots. Matplotlib can also be used for creating animated and interactive visualizations. It can also generate output in a variety of formats which includes PNG, SVG and PDF etc. Installing Matplotlib Matplotlib is not built into python. First, we need to install Matplotlib using the PIP package manager. pip install matplotlib If you are using Conda you can use the below command. conda install matplotlib You can refer to more about installation options on the Matplotlib installation page . Plotting Simple Graph using Matplotlib First, we need to import pyplot from Matplotlib library.  After that line, we give 2 python lists as arguments to plot()  function specifying Y values and X values for the graph. then we set the label for both the x...

Python Variables

Image
Creating a Python variable  In python, there isn't a way to declare variables what you can do is you can create a variable and assign a value same time.  name = "John" x = 8 You can use an expression as an assigned value in a variable. In the below scenario, expression evaluate first then that value is assigned to the variable on the left-hand side. value = 8 + 3 full_name = "John" + "Doe" Previously assigned variables can be used to build up the expression x = 6 y = 7 new_value = x + y Here x and y variables need to create earlier before it assigned to the new_value variable. You can also create multiple variables at once using a comma( , )   In the below example x , and y variables are created at once and assigned x to the value 6 and y to the value of  7 . x, y = 6 , 7 Nature of the python variables If you create python variables by assigning the same values then those vari...