104.1.2 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.
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()
Basics-What an error looks like?
---------------------------------------------------------------------------
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
Is there a difference between output of name and print(name)?
Out[7]:
'Practical business analytics \n using SAS'
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 “_”
File "<ipython-input-21-fd484b8e1634>", line 2
1x=20
^
SyntaxError: invalid syntax
File "<ipython-input-23-6d3a7516bd8a>", line 2
x.1=20
^
SyntaxError: invalid syntax
The next post is about Python objects.
Link to the next post : https://statinfer.com/104-1-3-python-objects/