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.
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.
- 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()
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
Basics-What an error looks like?
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
‘=’ is the assignment operator
x=20 x Out:
y=30 z=x*y z
del x #deletes the variable
Is there a difference between output of name and print(name)?
book_name="Practical business analytics \n using SAS" book_name
'Practical business analytics \n using SAS'
Practical business analytics using SAS
- Must start with a letter (A-Z or a-z)
- Can contain letters, digits (0-9), and/or underscore “_”
#Doesn't work 1x=20
File "<ipython-input-21-fd484b8e1634>", line 2 1x=20 ^ SyntaxError: invalid syntax
#works x1=20 x1
#Doesn't work x.1=20 x.1
File "<ipython-input-23-6d3a7516bd8a>", line 2 x.1=20 ^ SyntaxError: invalid syntax
#works x_1=20 x_1
The next post is about Python objects.
Link to the next post : https://statinfer.com/104-1-3-python-objects/