Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Python: String

Python Notes: Strings, Lists, Loops 1. What is a String? A string is a datatype, written as str in Python. It is a collection of characters: alphabets, special characters and numbers. It is written in single or double quotes. Use triple quotes ( ''' or """ ) for multiline text. It is index based. Indexing starts from 0. Negative indexing runs right to left: the last letter is -1 . Slicing syntax…

String is a datatype in Python, denoted as str. It comprises of various characters including alphabets, symbols and numbers. Strings are enclosed in single or double quotes, and for multiline text, triple quotes (either ''' or """) are used. They are indexed, starting from 0 and negative indexing runs from right to left, with -1 representing the last character.

Strings are immutable, meaning they cannot be changed once created; any modification results in a new string. For example, trying to change a string's character by assigning a new value directly to an index would result in a TypeError. However, new strings can be created by concatenating the original string with a new string or by slicing the original string.

The .format() method is used to format strings, allowing for the insertion of variables into string templates. Lists, on the other hand, are mutable and ordered collections written within square brackets []. They can hold mixed data types and duplicates, and their elements can be changed. Lists are also indexed like strings, but unlike strings, they allow modifications.

Functions like len() and list() can be used with lists. len() returns the count of elements in a list, while list() converts various data types into lists. The range() function generates sequences of numbers, which can be used in for loops for iteration.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Bloom filters for system design interviews, explained

Bloom filters for system design interviews, explained Somewhere in a design — a cache in front of a database, an LSM-tree storage engine, a web crawler deduplicating URLs — you hit the same waste: you…

  • Bloom filters are used to avoid costly lookups for non-existent items in system design interviews.
  • They provide a probabilistic structure with "definitely not" and "probably yes" outcomes.

Implementing HIPAA Safe Harbor (45 CFR § 164.514(b)(2)) CSV De-Identification 100% Client-Side in Vanilla JS

If you have ever tried to help a hospital lab, MD/PhD student, or clinical data team share a research CSV with an external collaborator or journal repository, you know the catch-22: Cloud SaaS…

  • HIPAA Safe Harbor 18-identifier transformation occurs client-side in Vanilla JS
  • ZIP codes and ages require specific handling per 45 CFR § 164.514(b)(2)
  • Audit certificates generated via SHA-256 fingerprints for data verification

More from Monday 23 November →