• No products in the cart.

104.1.2 Python Environment

Easy to use Python environment.

Link to the previous post : https://statinfer.com/104-1-1-introduction-to-python-and-ide-for-python/

We will be using Spyder as our python environment.

Spyder-Editor

This is where you write the code

  • To execute the code, select and hit Ctrl+Enter.
  • You can load old code files.
  • Code written in this editor is saved in .py format.
  • You can hit the tab button to see the autofill options on objects and function names.
  • You will be spending most of your time on editor.

Spyder-Console

  • This is where the code will be executed when you hit Ctrl+Enter in editor.
  • Helps us in code testing and debugging.
  • Helps us to avoid errors in the source code at the development phase itself.
  • Its usual practice to write a chuck of code in editor then execute it and see if it is working well or not.
  • You can toggle between Console and IPython Console.

Spyder – Variable explorer

  • Shows all the variables that are created in the current session.
  • Helps in physically checking the presence of objects that are created.
  • Shows a quick summary of type of object, size, length, sample values etc.,
  • We can run the code and see the objects getting created, also we can validate the data type and size of the object.

Basic Commands in Python

Before you code

  • Python is case sensitive.
  • Be careful while using the Variable names and Function names.
    • Sales_data is not same as sales_data
    • Print() is not same as print()

Basic Commands

In [1]:
571+95
19*17
print(57+39)
print(19*17)
print("Data Vedi")

# use hash(#) for comments
#Division example
34/56
96
323
Data Vedi
Out[1]:
0.6071428571428571

Basics-What an error looks like?

In [2]:
Print(600+900) 
#used Print() instead of print()
576-'96'
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-7-8cacbcbfb378> in <module>()
----> 1 Print(600+900)
      2 #used Print() instead of print()
      3 576-'96'
      4 

NameError: name 'Print' is not defined


Assigning and Naming convention

Assignment operator

‘=’ is the assignment operator

In [3]:
income=12000
income
Out[3]:
12000
In [4 ]:
x=20
x

Out[4]:
20
In [3]:
y=30
z=x*y
z
Out[3]:
600
In [4]:
del x #deletes the variable

Printing

In [5]:
name="Jack"
name
Out[5]:
'Jack'
In [6]:
print(name)
Jack

Is there a difference between output of name and print(name)?

In [7]:
book_name="Practical business analytics \n using SAS"
book_name
Out[7]:
'Practical business analytics \n using SAS'
In [8]:
print(book_name)
Practical business analytics 
 using SAS

Naming convention

  • Must start with a letter (A-Z or a-z)
  • Can contain letters, digits (0-9), and/or underscore “_”
In [9]:
#Doesn't work
1x=20
  File "<ipython-input-21-fd484b8e1634>", line 2
    1x=20
     ^
SyntaxError: invalid syntax
In [10]:
#works
x1=20 
x1
Out[10]:
20
In [11]:
#Doesn't work
x.1=20 
x.1
  File "<ipython-input-23-6d3a7516bd8a>", line 2
    x.1=20
      ^
SyntaxError: invalid syntax
In [12]:
#works
x_1=20 
x_1
Out[24]:
20

The next post is about Python objects.
Link to the next post : https://statinfer.com/104-1-3-python-objects/

Statinfer

Statinfer derived from Statistical inference. We provide training in various Data Analytics and Data Science courses and assist candidates in securing placements.

Contact Us

info@statinfer.com

+91- 9676098897

+91- 9494762485

 

Our Social Links

top
© 2020. All Rights Reserved.