Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
deleted 413 characters in body
Source Link
ostrokach

I would like to add two points to the discussion:

  1. You can use None instead on an empty space to specify "from the start" or "to the end":

     'abcde'[2:None] == 'abcde'[2:] == 'cde'
    

    This is particularly helpful in functions, where you can't provide an empty space as an argument:

     def remove_from_tailsubstring(s, n_char=0start, end):
         """Remove `n``start` characters from the beginning and `end` 
         characters from the end of string `s`.
    
         Examples
         --------
         >>> remove_from_tailsubstring('abcde', 0, 3)
         'abcde''abc'
         >>> remove_from_tailsubstring('abcde', 21, None)
         'abc''bcde'
         """
         return s[s[start:-n_char if n_char > 0 else None]end]
    
  2. Python has slice objects:

     idx = slice(2, None)
     'abcde'[idx] == 'abcde'[2:] == 'cde'
    

I would like to add two points to the discussion:

  1. You can use None instead on an empty space to specify "from the start" or "to the end":

     'abcde'[2:None] == 'abcde'[2:] == 'cde'
    

    This is particularly helpful in functions:

     def remove_from_tail(s, n_char=0):
         """Remove `n` characters from the end of string `s`.
    
         Examples
         --------
         >>> remove_from_tail('abcde', 0)
         'abcde'
         >>> remove_from_tail('abcde', 2)
         'abc'
         """
         return s[:-n_char if n_char > 0 else None]
    
  2. Python has slice objects:

     idx = slice(2, None)
     'abcde'[idx] == 'abcde'[2:] == 'cde'
    

I would like to add two points to the discussion:

  1. You can use None instead on an empty space to specify "from the start" or "to the end":

     'abcde'[2:None] == 'abcde'[2:] == 'cde'
    

    This is particularly helpful in functions, where you can't provide an empty space as an argument:

     def substring(s, start, end):
         """Remove `start` characters from the beginning and `end` 
         characters from the end of string `s`.
    
         Examples
         --------
         >>> substring('abcde', 0, 3)
         'abc'
         >>> substring('abcde', 1, None)
         'bcde'
         """
         return s[start:end]
    
  2. Python has slice objects:

     idx = slice(2, None)
     'abcde'[idx] == 'abcde'[2:] == 'cde'
    
added 191 characters in body
Source Link
ostrokach

I would like to add two points to the discussion:

  1. You can use None instead on an empty space to specify "from the start" or "to the end":

     'abcde'[2:None] == 'abcde'[2:] == 'cde'
    

    This is particularly helpful in functions:

     def remove_from_tail(strings, n_char=Nonen_char=0):
         """Remove `n_char``n` characters from the end of `string`string `s`.
    
         Examples
         --------
         >>> remove_from_tail('abcde', 0)
         'abcde'
         >>> remove_from_tail('abcde', 2)
         'abc'
         """
         return string[s[:-n_char if n_char >=> 10 else None]
    
  2. Python has slice objects:

     idx = slice(2, None)
     'abcde'[idx] == 'abcde'[2:] == 'cde'
    

I would like to add two points to the discussion:

  1. You can use None instead on an empty space to specify "from the start" or "to the end":

     'abcde'[2:None] == 'abcde'[2:] == 'cde'
    

    This is particularly helpful in functions:

     def remove_from_tail(string, n_char=None):
         """Remove `n_char` from the end of `string`."""
         return string[:-n_char if n_char >= 1 else None]
    
  2. Python has slice objects:

     idx = slice(2, None)
     'abcde'[idx] == 'abcde'[2:] == 'cde'
    

I would like to add two points to the discussion:

  1. You can use None instead on an empty space to specify "from the start" or "to the end":

     'abcde'[2:None] == 'abcde'[2:] == 'cde'
    

    This is particularly helpful in functions:

     def remove_from_tail(s, n_char=0):
         """Remove `n` characters from the end of string `s`.
    
         Examples
         --------
         >>> remove_from_tail('abcde', 0)
         'abcde'
         >>> remove_from_tail('abcde', 2)
         'abc'
         """
         return s[:-n_char if n_char > 0 else None]
    
  2. Python has slice objects:

     idx = slice(2, None)
     'abcde'[idx] == 'abcde'[2:] == 'cde'
    
Source Link
ostrokach

I would like to add two points to the discussion:

  1. You can use None instead on an empty space to specify "from the start" or "to the end":

     'abcde'[2:None] == 'abcde'[2:] == 'cde'
    

    This is particularly helpful in functions:

     def remove_from_tail(string, n_char=None):
         """Remove `n_char` from the end of `string`."""
         return string[:-n_char if n_char >= 1 else None]
    
  2. Python has slice objects:

     idx = slice(2, None)
     'abcde'[idx] == 'abcde'[2:] == 'cde'
    
lang-py