Practical Programming
An Introduction to Computer Science
Using Python 3
(Pragmatic Programmers)
(Pragmatic Bookshelf)
Paul Gries (著) Jennifer Campbell (著)
Jason Montojo (著) Lynn Beighley (編集)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 8(Storing Collections of Data Using Lists)、8.9(Exercises) 3-a, b, c.を解いてみる。
8.9(Exercises) 3-a, b, c.
コード(BBEdit)
sample3.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
appointments = ['9:00', '10:30', '14:00', '15:00', '15:30']
print(appointments)
print('a.')
appointments.append('16:30')
print(appointments)
print('b.')
appointments = ['9:00', '10:30', '14:00', '15:00', '15:30']
appointments += ['16:30']
print(appointments)
print('c.')
# a modified the list, b created a new list
print('a.')
appointments = ['9:00', '10:30', '14:00', '15:00', '15:30']
new_appointments = appointments.append('16:30')
print(appointments, new_appointments, sep='\n')
print('b.')
appointments = ['9:00', '10:30', '14:00', '15:00', '15:30']
new_appointments = appointments + ['16:30']
print(appointments, new_appointments, sep='\n')
入出力結果(Terminal, IPython)
$ ./sample3.py ['9:00', '10:30', '14:00', '15:00', '15:30'] a. ['9:00', '10:30', '14:00', '15:00', '15:30', '16:30'] b. ['9:00', '10:30', '14:00', '15:00', '15:30', '16:30'] c. a. ['9:00', '10:30', '14:00', '15:00', '15:30', '16:30'] None b. ['9:00', '10:30', '14:00', '15:00', '15:30'] ['9:00', '10:30', '14:00', '15:00', '15:30', '16:30'] $
0 コメント:
コメントを投稿