top of page
realcode4you

Python Basics Topics Practice Set Using Anaconda | Working with GitHub Repository Using Anaconda

Table of Contents

I. Environment set-up: Anaconda

  1. Anaconda Distributition by Continuum Analytics

  2. Using Anaconda

  3. Run Jupyter

  4. Create a Jupyter notebook

  5. Export Jupyter notebook and run it as a Python script

II. Create a Github account

  1. Install Github Desktop and create a GitHub account

  2. Create a new repository on GitHub

  3. Cloning Your Repository

  4. Add a new file to your repo

  5. The staging environment, the commit, and you

  6. Push a branch to GitHub

III. Python basics

  1. Data types

  2. Comparison Operators

  3. Logic Operators

  4. If, elseif, else Statement

  5. For Loops

  6. 6. While Loops

  7. 7. Range

  8. 8. List Comprehension

  9. 9. Functions

  10. 10. Lambda expression

  11. 11. Map and filter

  12. 12. Methods

IV. Python basics – Exercises



I. Environment set-up: Anaconda

So this course uses the Python programming language throughout it. So the first thing we need to do is make sure you have a Python development environment set up on your personal computer. So we will walk through installing a package called Anaconda which has both the development environment and all the Python packages you need pre-installed. It makes life really easy.


1. Anaconda Distributition by Continuum Analytics

Download the installer (Python 3.6 version) for your OS

Run the installer


2. Using Anaconda

If you want to install a new package into your Anaconda, type:

conda install <package>


3. Run Jupyter

The Jupyter Notebook App can be launched by clicking on the Jupyter Notebook icon installed by Anaconda in the start menu (Windows) or by typing in a terminal (cmd on Windows):


jupyter notebook

This will launch a new browser window (or a new tab) showing the Notebook Dashboard, a sort of control panel that allows (among other things) to select which notebook to open.

When started, the Jupyter Notebook App can access only files within its start-up folder (including any sub-folder). If you store the notebook documents in a subfolder of your user folder no configuration is necessary. So make sure you go to the folder you want (using cd <folder> in terminal) before starting Jupyter (jupyter notebook).

For more configurations, see:



4. Create a Jupyter notebook

In the Notebook Dashboard, select New → Notebooks → Python 3.

Click on the new notebook file. It will open the Jupyter Notebook App.

In the notebook cell, type:

print("Hello World")

Run cell, press: CTRL+ENTER

Run cell and insert next, press: ALT+ENTER

Run cell and select next, press: SHIFT+ENTER

Remember to save your notebook when done (although it will automatically do the save for your every 3 mins): CTRL+S


5. Export Jupyter notebook and run it as a Python script

There are two ways to run the Python code in Jupyter notebook as a program:

Select File → Download as → Python(.py)

On the command line, type:

jupyter nbconvert --to script <NOTEBOOK_NAME>.ipynb

Run the script:

python <NOTEBOOK_NAME>.py



II. Create a Github account

1. Install Github Desktop and create a GitHub account

Download and follow the instructions here (1) to install Github Desktop (if it's not already installed). Once you've done that, create a GitHub account here (2). (Accounts are free for public repositories, but there's a charge for private repositories.)

Note:


2. Create a new repository on GitHub

A repository is where you project will be host on Github, so you can keep a history of changes (versions) of your project, and can share your code it with everyone, and allow team work on the same project. Think of a repository as if it was a folder on your Dropbox with your project, but with more functionalities for version control and team work.

To create a new repo on GitHub, log in and go to the GitHub home page. You should see a green '+ New repository' button:

After clicking the button, GitHub will ask you to name your repo and provide a brief description:



When you're done filling out the information, press the 'Create repository' button to make your new repo.


Note: you can also create a Repository using Github Desktop directly.


3. Cloning Your Repository

Now you can Clone your Github repository to your local machine, this will link your Github repository with your local repository, so that every change you make you project can be pushed to your online repo.


Just choose a directory in your local machine where you want to put your project files, and use the option Clone a repository on Github Desktop to link and synchronize your Github repo with your local repo.


4. Add a new file to your repo

Go ahead and add a new file to the project, using any text editor you like or running a touch command.

Once you've added or modified files in a folder containing a Git repo, git will notice that changes have been made inside the repo. But, git won't officially keep track of the file (that is, put it in a commit - we'll talk more about commits next) unless you explicitly tell it to.


touch test_file.txt


After creating the new file, you can check on GitHub Destop that your new file has been identified.



5. The staging environment, the commit, and you


One of the most confusing parts when you're first learning git is the concept of the staging environment and how it relates to a commit.

A commit is a record of what files you have changed since the last time you made a commit. Essentially, you make changes to your repo (for example, adding a file or modifying one) and then tell git to put those files into a commit.

Commits make up the essence of your project and allow you to go back to the state of a project at any point.


So, how do you tell git which files to put into a commit? This is where the staging environment or index come in. As seen in Step 3, when you make changes to your repo, like adding a file, git notices that a file has changed but won't do anything with it (like adding it in a commit). To add a file to a commit using GitHub Desktop, just add a Summary message to your commit and click in Commit to Master.

Now you can see you committed files in your repo’s history


Note: The staging environment, also called 'staging', is the new preferred term for this, but you can also see it referred to as the 'index'.


The message at the end of the commit should be something related to what the commit contains - maybe it's a new feature, maybe it's a bug fix, maybe it's just fixing a typo. Don't put a message like "asdfadsf" or "foobar". That makes the other people who see your commit sad. Very, very, sad.


6. Push a branch to GitHub

Now we'll push the commit in your branch to your new GitHub repo. This allows other people to see the changes you've made, this will update all changes you made into your Github repository. To push changes onto a new branch on GitHub Desktop, just go to Repository -> Push.


And that’s all folks, now you can see your changes on your Github repository.



III. Python basics

Please note, this is not meant to be a comprehensive overview of Python or programming in general, if you have no programming experience, you should probably take other courses.

This notebook will just go through the basic topics in order:

  • Data types

o Numbers

o Strings

o Printing

o Lists

o Dictionaries

o Booleans

o Tuples

o Sets

  • Comparison Operators

  • if,elif, else Statements

  • for Loops

  • while Loops

  • range()

  • list comprehension

  • functions

  • lambda expressions

  • map and filter

  • methods


1. Data types

1.1. Numbers


1.2. Variable assignment

1.3. Strings

1.4. Printing

1.5. Lists



1.6. Dictionaries

1.7. Booleans

1.8. Tuples

1.9. Sets

2. Comparison Operators


3. Logic Operators

4. If, elseif, else Statement

5. For Loops

6. While Loops


7. Range


8. List Comprehension


9. Functions


10. Lambda expression





1 Comment


jaro
jaro
Sep 16

I really appreciate how clearly you’ve outlined the steps for setting up Python with Anaconda and GitHub in this blog! The practical guide is perfect for beginners to get hands-on with Python Basics. For those looking for a more detailed introduction to learning Python, I recommend checking out this comprehensive guide (jaroeducation.com/blog/learn-python-from-scratch-in-2024-the-ultimate-guide/). Thanks for sharing these valuable resources!


Like
bottom of page