Strings

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What's the fill character in the following format specification? {score: >4}

space character

Write a complete replacement field that assigns a field with named value "count" a field width of 5.

{count:5}

Write a statement that uses the join() method to set my_str to 'NewYork', using the list x = ['New', 'York'] my_str = ?

''.join(x)

Write a statement that uses the join() method to set my_str to 'images.google.com', using the list x = ['images', 'google', 'com'] my_str = ?

'.'.join(x)

Write a statement that replaces the separators in the string variable title from hyphens (-) to colons (:) title = 'Python-Lab-Warmup' tokens = title.split('-') title = ?

':'.join(tokens)

What's the fill character in the following format specification? {score:*>4}

*

What is the output? my_str = 'http://reddit.com/r/python' *print*(my_str[17:])

/r/python

Fill in the string that results from evaluating the given expression. '{x:.1f}'.format(x=5) '5._____'

0

Fill in the string that results from evaluating the given expression. '{x:.3f}'.format(x=5) '5.________'

000

Complete the format specification to assign a field width of 10 characters. {name: ? }

10

Fill in the string that results from evaluating the given expression. '{x:4.1f}'.format(x=5) '________'

5.0 (one space before the "5")

Fill in the string that results from evaluating the given expression. '{x:.3f}'.format(x=5.25) '________'

5.250

Fill in the string that results from evaluating the given expression. '{x:.3f}'.format(x=5.2589) '________'

5.259

If *name = 'Sally'*, what is the result of: *{name:@>8}*?

@@@Sally

What is the output? my_str = 'Agt2t3afc2kjMhagrds!' *print*(my_str[0:5:1])

Agt2t

What is the output? my_str = 'Agt2t3afc2kjMhagrds!' *print*(my_str[::2])

AttackMars

For each question, determine the value of the given expression. '{name:<5}'.format(name='Bob')

Bob (2 spaces after "b")

For each question, determine the value of the given expression. '{name:>5}'.format(name='Bob')

Bob (2 spaces before "B")

For each question, determine the value of the given expression. '{name:^5}'.format(name='Bob')

Bob (one space before "B" and one space after "b")

For each question, determine the value of the given expression. x = '{name:<5}{score:<2}'.format(name='Bob', score=1)

Bob 1 (two spaces after "b" and one space after "1")

For each question, determine the value of the given expression. '{name:<5}{score:>2}'.format(name='Bob', score=1)

Bob 1 (two spaces after "b" and one/two space(s) after "1")

Determine whether the given expression evaluates to True or False. *'1 2 3 4 5'.isdigit()* True or False

False

Determine whether the given expression evaluates to True or False. *'HTTPS://google.com'.isalnum()* True or False

False

Determine the output of the following code: my_str = 'The cat in the hat' *print*(my_str[0:3])

The

Determine whether the given expression evaluates to True or False. *'HTTPS://google.com'.startswith('HTTP')* True or False

True

Determine whether the given expression evaluates to True or False. *'LINCOLN, ABRAHAM'.isupper()* True or False

True

Determine whether the given expression evaluates to True or False. *'\n \n'.isspace()* True or False

True

Determine the output of the following code: my_str = 'The cat in the hat' *print*(my_str[3:7])

cat (*one space to the right*)

What is the output? my_str = 'http://reddit.com/r/python' protocol = 'http://' *print*(my_str[len(protocol):])

reddit.com/r/python


Kaugnay na mga set ng pag-aaral

Discovery Education Unit 1: Process of Science

View Set

Sexual Assault Prevention for Undergraduates Post-Course Exam

View Set

Biology Chapter 15 and 23 - Quiz Questions

View Set

Unit 6: Operant Conditioning Consequences Examples

View Set

COIS 1010 - Test #2 Terms (Part 2)

View Set