Elements of Python

damjaeng-i·2022년 7월 31일
0

2022 PY4E

목록 보기
4/18
post-thumbnail
post-custom-banner

Elements of Python

  • Vocabulary/Words

    : Variables and Reserved words (Chapter 2)

  • Sentence structure

    : Valid syntax patterns (Chapter 3-5)

  • Story structure

    : Constructing a program for a purpose

Reserved Words

: You cannot use reserved words as variavle names / identifiers

Falseclassreturn is finally
Noneifforlambdacontinue
Truedeffromwhilenonlocal
anddelglobalnotwith
aseliftryoryield
assertelseimportpassprint
breakexceptinraise

Python Scripts

  • Interactive Python is good for experiments and programs of 3-4 lines long.
  • Most programs are much longer, so we type them into a file and tell Python to run the commands in the file.
  • In a sense, we are “givind Python a script”.
  • As a convention, we add “.py” as the suffix on the end of these files to indicate they contain Python.

Program Steps or Program Flow

  • Like a recipe or installation instructions, a program is a sequence of steps to be done in order.
  • Some steps are conditional - they may be skipped. → If
  • Sometimes a step or group of steps is to be repeated.
  • Sometimes we store a set of steps to be used over and over as needed several places throughout the //Sprogram. (Chapter 4)
//Sequential 
name = input('Enter file:')
handle = open(name, 'r')

counts = dict()

//Repeated
for line in handle:
		words = line.split()
		for word in words:
				counts[word] = counts.get(word, 0) + 1
bigcount = None
bigword = None
for word.count in counts.items():
		//Conditional 
		if bigcount is None of count > bigcount:
				bigword = word
				bigcount = count
print(bigword, bigcount)

Summary

  • This is a quick overview of Chapter 1
  • We will revisit these concepts throughout the course
  • Focus on the big picture
profile
목표 : 부지런한 개발자
post-custom-banner

0개의 댓글