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
. A collection of programs designed to create and manage databases is called a(n))
Daniel [21]

Answer:

Database Management System.

Explanation:

Database Management System is the collection of programs and data used to create ,define and manipulate the database.

There are several database management systems present and some of them are as following:-

  1. RDBMS (Relational Database Management System)
  2. No SQL DBMS
  3. CDBMS(Columnar Database Management System).
  4. IMDBMS(In-Memory Database Management System).
6 0
2 years ago
8.10 Code Practice Question 3
Alchen [17]

terms = ["Bandwidth", "Hierarchy", "IPv6", "Software", "Firewall", "Cybersecurity", "Lists", "Program", "Logic",

        "Reliability"]

def swap(arr, in1, in2):

   w = arr[in1]

   arr[in1] = arr[in2]

   arr[in2] = w

print(terms)

swap(terms, 5, 1)

swap(terms, 2, 4)

swap(terms, 3, 5)

swap(terms, 5, 6)

swap(terms, 6, 8)

swap(terms, 8, 9)

print(terms)

This is how I interpreted the question. If I need to make any changes, I'll do my best. Hope this helps though.

4 0
2 years ago
Can someone please answer this for me ? What is data centre virtualization?
castortr0y [4]
Data center virtualization is the process of designing, developing and deploying a data center on virtualization and cloud computing technologies. It primarily enables virtualizing physical servers in a data center facility along with storage, networking and other infrastructure devices and equipment.
3 0
2 years ago
Nathan wants to make the quotation stand out further. Which order of steps does he need to follow to do this task?
Alina [70]

Answer:

B.

Explanation:

Go to the Borders and Shading option, click the Shading tab, and click the color under the Fill option.

5 0
3 years ago
Read 2 more answers
You live "out in the middle of nowhere" and feel there is no need to protect your internet connection because there is no one th
dlinn [17]
Yes, it put you at risk, and could have actually gotten you killed.
4 0
3 years ago
Other questions:
  • Your dad just purchased a new desktop with Windows 8 Professional. He is calling you, informing you that he is unable to remote
    9·1 answer
  • NEED THIS NOW PLEASE!!!! (I AM NOT JOKING I HAVE TO SUBMIT IN 5 MINUTES)
    13·2 answers
  • Briley has all the hardware she needs to construct a fully functional personal computer. She connects the various components and
    7·1 answer
  • Write a code to define a structure named student, which includes name, student number and email address
    5·1 answer
  • bro this scared me, i thought i just got hacked, could someone explain why when i went to ask a question, it kicked me out my ac
    9·2 answers
  • Users of Adobe Reader, created by Adobe Systems Incorporated, are prompted to provide feedback on their experiences with the sof
    7·1 answer
  • What can you use on Code.org's Web Lab to find and fix problems when you are writing code for your website?
    13·1 answer
  • What does an "embedded video" mean
    7·1 answer
  • How do i dos someone? I wanna mess with my friend
    10·1 answer
  • Pls need this asap
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!