Python study note_003

After understanding the sample code in Chapter 1 of the book, I modified it as follows for practice.

--Point: --Use backslash () (Enter "option + " on Mac) --If you use a backslash in a string, the space after the line break will be output as it is. --You can use a backslash between two line breaks to concatenate without spaces.

sample_01.py


import random

#Define a list
subjects = ['I\
Is','hole\
Or']
verbs = ['Like'\
         'is',
         'Hate'\
         'is']
nouns = ['Summer is','Autumn']

#Select one element from the list
subject = random.choice(subjects)
verb = random.choice(verbs)
noun = random.choice(nouns)

#Concatenate words to make a phrase
phrase = subject + ' ' + noun + ' ' + verb

#Output phrase
print(phrase)

#One of the output results
#You like autumn

Recommended Posts

Python study note_002
Python study note_004
Python study note_003
Python note
[WIP] Fluent Python Study Note
Python programming note
[Python] Learning Note 1
Python study notes _000
Python study notes_006
Python study notes _005
Jupyter Study Note_002
[Note] openCV + python
Python beginner's note
Python study notes_001
Jupyter Study Note_003
Jupyter Study Note_007
Jupyter Study Note_005
Python study day 1
[Note] future sentence ~ Python ~
[Note] File reading ~ Python ~
Note to daemonize python
Note: python Skeleton Nya
Python basic grammar note (4)
Python basic grammar note (3)
Python Tkinter Primer Note
Note
Python
Study Python with Google Colaboratory
Python Input Note in AtCoder
[Note] Operate MongoDB with Python
Study from Python Hour3: Functions
Note
Note
python pandas study recent summary
3 months note for starting Python
Study from Python Hour4: Object-oriented ①
[AtCoder] ABC165C Personal Note [Python]
Note that it supports Python 3
A note about [python] __debug__
Python Note: About comparison using is
[Note] Project Euler in Python (Problem 1-22)
Python: A Note About Classes 1 "Abstract"
selenium case study summary python pyCharm
(Note) Be careful with python argparse
Study from Python Hour2: Control statements
Study on Tokyo Rent Using Python (3-2)
[Note] Hello world output with python
boto3 (AWS SDK for Python) Note
Foreign Key in Python SQLite [Note]
Study on Tokyo Rent Using Python (3-3)
Study, number guessing game in Python
Study Note 9_Install Jenkins on CentOS7
Python Note: Get the current month
A note about mock (Python mock library)
Basic study of OpenCV with Python
kafka python
Python & Machine Learning Study Memo: Environment Preparation
Django note 4
A note where a Python beginner got stuck
Python Summary
Built-in python