Top Banner
Python Review Intro to Git Eric J Nguyen
23

Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Mar 12, 2018

Download

Documents

votuyen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Python ReviewIntro to Git

Eric J Nguyen

Page 2: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Python Overview

● Based on Python 3.4.4 specifications● Assumed that you know Python● Derived from Dr. Mitra’s CS 303E Notes

Page 3: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Conventions

● Use a plain text editor○ Notepad++, TextWrangler, Sublime Text, etc.○ Don’t use Notepad (Win) or TextEdit (Mac)!

● Spaces, not tabs○ Google “Indent using spaces in <TextEditor>”○ Indents matter in Python

● Unix line endings○ Google “Unix line endings in <TextEditor>”

Page 4: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Hello World

# This is a comment# This is a basic Hello World program

print(“Hello World!”)

Page 5: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Variables

● Start with a letter or underscore● Contains letters, digits, or underscores

x = 1y = 2

Page 6: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Operators

● Arithmetic○ + - * / // % **

● Comparison○ == != > >= < <=

Page 7: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

User Input

nameStr = input("Name: ")age = eval(input("Age: "))

Page 8: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Functions

def functionName(): return 7

def functionName2(arg1, arg2): return arg1 + arg2

Page 9: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Conditionalsif (someCondition): ..do stuff..else: ..do other stuff..

if (someCondition): ..do stuff..elif: ..do cool stuff..else: ..do other stuff..

Page 10: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Loops

for i in range(0,10): print(i)

break and continue

Page 11: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

String

Ordered list of characters

string = "Hello World!"print(string)print(string[1])print(string[1:])print(string[:-2])

Page 12: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

File Input

inFile = open("inputFile.txt","r")

for line in inFile: print(line.rstrip("\n"))

inFile.close()

Page 13: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

File Output

outFile = open("outputFile.txt","w")outFile.write("Hello World!\n")outFile.close()

# To AppendoutFile = open("outputFile.txt","a")outFile.write("Hello World 2!\n")outFile.close()

Page 14: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

List

Basic ordered data structure

l = ["a", "b", "c", 2, 3, 4]for i in range(len(l)): print(l[i])for e in l: print(e)

Page 15: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Dictionary

Key-value store

phoneNums = {}phoneNums['Eric'] = '512-555-0123'phoneNums['Daniel'] = '512-555-0124'

phoneNums['Eric'] = '512-555-0000'

Page 16: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Python Questions?

Page 17: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Git Overview

● Version Control○ Managing different versions of code○ See the code “history”○ Everything is “local” until you push to “remote”○ GitHub is our “remote”

● Collaboration○ Many people working on the same code at once○ Merge the changes later○ No need to email/Dropbox the “latest version” of code

Page 18: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Git Terms

● Working Directory: current folder of actual files● Commit: single set of code changes

○ Uniquely identified by a SHA1 hash (fingerprint)● Branch: ordered set of commits

○ Timeline of code changes● Repository: set of branches

Page 19: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Starting Out

● Create your repository (“repo”)● Add your code● Make your first commit● Push your repo

Page 20: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Workflow

● Make your changes● Commit● Pull and merge from remote (sometimes)● Push

Page 21: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Merge Conflicts

● Can’t decide how to resolve two conflicting changes

● Manually resolve the conflict and commit the change

● Push

Page 22: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

More Advanced Stuff

● Use command line git○ Feel free to use either GitHub Desktop or

command line git

Page 23: Python Review Intro to Git - Department of Computer Sciencescohen/cs327e_spr16/project/python_git.pdf · Conventions Use a plain text editor Notepad++, TextWrangler, Sublime Text,

Git Questions?