Python w/Flask
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    ###### tags: `Lesson Notes` `Python` `Fundamentals` `PythonFlask2021` # Intro to Python ## System Set up ### Python installation #### Step 1 - Check to see if you already have it Is Python already on your system? Check by using the following commands (try each one just to be sure): 1. python --version 2. python3 --version 3. py --version On some computers with python 3 installed you will get a version back for both 1 and 2. Some computers will only give a version using 1 of the 3. One of my computers only responds to py, however most will print a version number for python or python3. So if you see a version number then procede to step 3 #### Step 2 - Download Python If it isn't installed then lets get it on there... your gonna want it * Windows Users follow this link [Windows Download](https://www.python.org/downloads/windows/) * Mac Users follow this link [Mac Download](https://www.python.org/downloads/mac-osx/) Now once that is installed your going to want to check which way your computer likes to access python so repeat step 1. If 1 and 2 work you will just use 2 most of the time. ### VS Code Extension #### Step 3 - Adding a python extension to VS Code Although not required it can help for you to have a python extension for VS Code. We recommend the following: * Python (also seen as ms-python.python) Having this installed can help you a lot. ## Folders Alrighty then our systems are now set up and ready to go....wait nope no coding yet...still got more to do 1st #### Step 4 - Get those folders set up Yup the ol get the folders ready thing again. Trust me it's important. Here is a good recommended structure for you folders (if they have a ^ at the end they are git folders and assignments otherwise they should just be plain old folders) * python_stack * python * fundamentals * forLoopBasicI ^ * functionsBasicI ^ * pythonOOP * flask And so on. Now that that is done (and you can always add more folders later) lets move on and play with some code ## Let's print some strings So before we get started just how close to JavaScript is Python? Well you will certainly find things familiar for some things that is for sure. So lets get to the basics ### How do we print: Once you have your function or print statement in your .py file lets say hello.py and your terminal is in the folder location of said file type in the terminal the following: python hellp.py (or what ever the file name is) Just don't forget if your device doesn't print the version with python to use what does. ### console.log vs print: So in JS we use console.log to print things to the terminal or the console. Why? Well the main or biggest reason is because we want to know that the function we are working with is well... working. By printing things to the console we can use that as a debugging tool. On the surface print is the same thing. It is a way to access the function with out needing to interact with a web page So lets look at a variable and print it to the terminal and compare JS vs Python JS: ``` var x = "Hello World" console.log(x) ``` Python: ``` x = "Hellow World" print(x) ``` Ok so not so scary after all right? Ok so now that the super scary part is over lets see different ways we can print a string, we are going to first declare some variables and then add them into a sentence. #### Method 1: String Literals We actually already did this in a way but here you go: ``` print("I am a string literal") ``` #### Method 2: Concatenating strings and varables * Version 1: ``` coding = "Python" print ("I'm not scared of", coding) ``` Written as is this will print as follows in the terminal: I'm not scared of Python * Version 2: ``` coding = "Python" print("I'm not scared of" + coding) ``` Written as is this will print as follows in the terminal: I'm not scare ofPython :::info Nope that is not a goof on me.... that is how it will print. ::: Lets fix it ``` coding = "Python" print("I'n not scare of " + coding) ``` Adding in that space after the word of will allow it to print as follows: I'm not scare of Python Personally Version 1 is better.... less hassle with spacing. #### Method 3: String Inerpolation What the what? Don't worry it's just fancy speak for injecting variables into your strings. Feel better now? Ok Good. So there are a few way we can go about this too. I have my favorite... ##### Version 1: F-strings (Literal String Interpolation): This is new as of python version 3.6 (so if you are running and older version this won't work for you) ``` location = "online" school = "Coding Dojo" time = 20 print(f"We are learning {location} through {school}, and the program is {time} weeks long.") ``` Not too bad... seems easy and it would print as follows: We are learning online through Coding Dojo, and the program is 20 weeks long. ##### Version 2: string.format(): This method is most likely what you will find most often when searching on the internet. ``` location = "online" school = "Coding Dojo" time = 20 print("We are learning {} through {}, and the program is {} weeks long.".format(location, school, time)) ``` This one can get you in trouble.....ok not really but if you don't put the variable names in the right order in the format() you might get a goofy reading string. So make sure you pay attention. This one still isn't too bad but you can see can lead to issues if your not careful. ##### Version 3: %.formatting Not this guy is even older than version 2. Hopefully you don't run across it in the wild, but you just never know. ``` location = "online" school = "Coding Dojo" time = 20 print("We are learning %s through %s, and the program is %s weeks long." % (location, school, time)) ``` Yea I don't like this one either. But like I said it can be found in the wild so you should know what it looks like. So as you can see there are a few ways to print things to your terminal in terms of strings. Some are just crazy, and some have caught up with the times and aren't so bad.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully