1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ehidna [41]
1 year ago
12

Assume the variable myWord references a string. Write a statement that uses a slicing

Computers and Technology
1 answer:
givi [52]1 year ago
3 0

Answer:

"myWord[-5:]"

Explanation:

So whenever you slice a string, the syntax in python is expressed as:

string[a:b:c]

where a=start index (this is included in the sliced string)

b = end index (this is excluded from the sliced string)

c = increment

If any of these are included, they are set to default values, where a=0, b=len(string), and c=1.

The increment isn't necessary here, and it's just so you know the syntax a bit more

Anyways, I'm assuming when the question asks to display "the last 5 characters in the string" it means in order? e.g "abcdefghijk" -> "ghijk" and not "abcdefghijk" -> "kjihg"

The last piece of information to know is what a negative index represents.

For example if I have the piece of code

"

string = "hello world"

print(string[-1])

"

This will output "d", and the negative 1 represents the last letter. If you did -2, it would output the 2nd to last letter and so on.

So to print the last 5 characters, we simply use the -5 as the starting index.  

"

string = "hello world"

print(string[-5:])

"

This will print "world" or in other words, the last 5 letters. The reason for this is because the -5 in the first spot means the starting index is the 5th to last letter, and when you have the : after the -5, this is the way of telling python you're slicing the string, and not indexing 1 character. You don't need to include another value after that, because it will default to the last index of the string, or more specifically the last index + 1, since the last index is still included.

So the last thing to know, is that if the string isn't greater than 5 characters, it just prints the entire string, and no errors are raised. You can test this out your self as well. So whenever you have a string that's less than 5 characters the entire string is outputted.

You might be interested in
Medium-term goals describe what you want your business to achieve (a) in ten years, (b) in terms of market share, (c) in two to
77julia77 [94]

The correct answer to this question is Choice C- in two to five years.

Your medium-term goals may build upon your short term goals. For example, your short term goal may be to save $1,000. Building upon this, your medium-term goal could be to save $5,000.

3 0
3 years ago
How to save a file for the first time?​
White raven [17]

by typing ctrl+ s on keyboard

7 0
3 years ago
Read 2 more answers
Where is the spell checker found in excel?
fenix001 [56]
Except keyboard of F7 and Spell Checkbutton in toolbar, you are also able to apply Spelling check command fromExcel 2007/2010/2013/2016 Ribbon: Click the Review tab; Go to Proofing group; Then you will view the Spellingbutton , that's Spell Check command.



hope this helps
5 0
3 years ago
Read 2 more answers
If you receive an email message you suspect is spam, what should you do?
Alla [95]

Answer:

A.  delete the message without opening it.

Explanation:

Never open emails you don't know who sent it, it could be a hacker trying to get your personal/financial information.

6 0
3 years ago
Which term is used to describe individuals who want to attack computers yet lack the knowledge of computers and networks needed
ludmilkaskok [199]

Answer:

script kiddies

Explanation:

script kiddies is used to describe individuals who want to attack computers yet lack the knowledge of computers and networks needed to do so

8 0
3 years ago
Other questions:
  • A drop-down menu must be contained by
    5·1 answer
  • Jeremy’s office is in an earthquake prone area. His web server is in his office. What step should he take to protect the data on
    5·1 answer
  • Telepresence provides the opportunity for people to work from home and attend virtually. True False
    5·2 answers
  • One group of students did an experiment to study the movement of ocean water. The steps of the experiment are listed below.
    10·1 answer
  • Two technicians are discussing a resistance measurement. Technician A states that components being measured should be removed or
    10·1 answer
  • IT investments can lead to developing IT capabilities and dynamic IT competencies, which can lead to achieving the following six
    5·1 answer
  • This needs to be written in Java.
    11·1 answer
  • Select the correct answer from each drop-down menu.
    7·2 answers
  • Which component of the windows desktop allows you to retrieve files that have recently been deleted?
    11·1 answer
  • In the language of the World Wide Web, "this page cannot be displayed" means A. your computer's software is damaged. B. the ISP
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!