How to check if string contains forward slash in python

I am a beginner to Python so bear with me. Basically I am searching a particular table cell for the forward slash character. If the cell contains that character, I want to delete the entire row.

counter = 0
for row in table:
    if row[7].find["/"] != -1:
        del table[counter]
        continue
    counter+=1

The code above never detects the forward slash but finds any other character I substitute for forward slash. Any help would be much appreciated.

asked Dec 10, 2010 at 17:03

2

There's so many things wrong with that code it's easier to just re-write it.

table[:] = [row for row in table if '/' not in row[7]]

answered Dec 10, 2010 at 17:05

4

Could you not just maybe do..

for row in table:
    if '/' in row[7]:
        row.delete[]

Or if you really need the counter to del the row from the table, then just put the counter back in.

answered Dec 10, 2010 at 17:09

IacksIacks

3,6392 gold badges20 silver badges24 bronze badges

7

Python Programming

s = 'canada/japan/australia'
l = s.split['/']

print[l]

Output

['canada', 'japan', 'australia']

Check if given String is Palindrome in Python

Cutting and slicing strings and examples of substring

Convert String variable into float, int or boolean

Convert Camel Case to Snake Case and Change Case of a particular character in a given string

Reverse a string in different ways

Generate random string of N characters

How do I trim white space in Python?

Different ways to pad or add zeroes to string

How to check if the string is empty or blank?

Different ways to count the number of occurrences of a character in a string

How to check if string ends with one of the strings from a list?

How to Split Strings on Multiple Delimiters or specified characters?

How do I append one string to another?

How do I iterate over a string in Python?

How to strip punctuation from a string in Python?

How to convert a list into string?

How to convert JSON into String?

How to compare strings in Python?

How to check whether a string starts with XXXX in Python?

How to sort a list of strings?

Different ways to mesh or interleave two strings together in Python

How do I compare two strings in Python?

How to compare two string with some characters only in Python?

Why does comparing strings using either '==' or 'is' sometimes produce a different result?

How to compare individual characters in two strings in Python?

How can the indices of a string be compared for equality in Python?

How to compare a string with a Enum in Python?

String comparison in Python is vs ==

Comparing characters in a string in Python

Python compare two strings and check how many chars they have in common

How to check if a variable is equal to one string or another string?

Python compare two strings retain difference from one end

Checking if two strings contain the same characters in Python

Find the position of difference between two strings

How can I check if a string has the same characters in Python?

How to check if two strings contain same letters and numbers in Python?

How to use string.replace[] in Python?

How to replace multiple substrings of a string in Python?

How to replace the first character alone in a string in Python?

How to replace specific instance of string in string in Python?

Python to replace strings starting from the end?

Concatenate strings in multiline in Python

Replacing a character from a certain index in Python?

Python string replace multiple occurrences

Python string replace character

How to concatenate a fixed string and a variable in Python

How to concatenate two variable one is string and other is int in Python?

Concatenate strings and variable values in Python

Append several variables to a list in Python

How can I concatenate str and int objects?

TypeError: cannot concatenate 'str' and 'float' objects Python

How to remove leading and trailing spaces in Python?

How do I trim whitespace in Python?

Trim specified number of spaces from left and right in Python?

Trim specific leading and trailing characters from a string in Python

How do I strip all leading and trailing punctuation in Python?

How to remove leading and trailing zeros in a string in Python?

Remove last character if it's a backslash in Python

How to capitalize a string in Python?

How to change a string into uppercase in Python?

How can I capitalize the first letter of each word in a string in Python?

Capitalize a string in Python

Randomly capitalize letters in string in Python

Capitalize first letter of the first word in a list in Python

How do I lowercase a string in Python?

Convert UPPERCASE string to sentence case in Python

Change some lowercase letters to uppercase in string in Python

Check if string is upper, lower, or mixed case in Python

How to capitalise last letter of string in Python?

How to capitalize first and last letters of line in a Python string?

How to capitalize every 3rd letter of string in Python?

Capitalizes a string according to the Index positions in Python

Capitalise every second letter in a string in Python?

Extract Uppercase and Lowercase characters from String Python?

Count number of Uppercase and Lowercase characters in String in Python?

How to get the size of a string in Python?

How to get size of string in bytes in Python

How can I fill out a Python string with spaces?

How to pad with n characters in Python?

Python padding strings of different length

Python String Padding

How to pad a numeric string with zeros to the right in Python?

How to pad zeroes to a string?

How to pad a string with leading zeros in Python3?

Dynamically calculated zero padding in format string in python

Format integer as string with leading zeros in Python?

Python string formatting padding negative numbers

How to add X number of spaces to a string in Python

Display string multiple times in Python

Python - How to add space on each 4th character?

Paragraph formatting in Python

Python regex add space whenever a number is adjacent to a non-number

How can I add space between parentheses and string in Python?

Add space between number and string in Python

Python string formatting fixed width

How to replace all characters in a string with one character in Python?

Find a whole word is in given string in Python?

Python pad string to fixed length

Python pad string with zeros

Efficient way to add spaces between characters in a string in Python

How to get the position of a character in Python?

How to find all positions of a character in a string in Python?

Find a substring in a string and returning the index of the substring in Python

How to find all occurrences of a substring?

Example of string find in Python

Python Find pattern in a string

Find index of last occurrence of a substring in a string in Python

Python find first occurrence of character after index

How to find all the indexes of all the occurrences of a word in a string in Python?

Python split string into multiple string

Split string on backslash in Python

Splits the string at every underscore and stop after the Nth position

How to split a string into an list of characters in Python?

Split string into two parts only in Python

Split a string only by first space in Python

Split string in Python to get first value?

Split a string on the last occurrence of the delimiter in the string in Python

Split a string by the position of a character in string in Python

Split string into strings by length in Python

Split string on forward slash in Python

Python split on newline

How to split string without losing split character in Python?

Split on non alpha-numeric and keep the separators in Python

Splitting a string with multiple delimiters in Python

Split string only after double quotes in Python

How to split a byte string into separate bytes in Python?

Split a string at the words AND OR NOT keeping the separators

How can I find the first occurrence of a sub-string in a Python string?

How to split a string by multiple punctuations with Python?

Split string on punctuation

Split Strings into words with multiple word boundary delimiters

Python count number of string appears in given string

Python center align the string using a specified character

Check if the string ends with given string or character in Python

Python set the tab size to the specified number of whitespaces

Check if all the characters in string are digits in Python

Find last business or working day of a month in Python

Follow @Pythonblogging

PYTHON TUTORIAL

Variables If…Else While Loop For Loops Lists Dictionary Tuples Classes and Objects Inheritance Method Overriding Operator Overloading NumPy

PYTHON EXAMPLES

Basic Date Time Strings Pandas Matplotlib NLP Object Oriented Programming Twitter Data Mining

TensorFlow BASIC

Introduction and Installation Hello World Tensors Tensor Calculations Computation Graph Variables

©2017-20 PythonProgramming.in

Drop us a line

To top

How do I check if a string has a slash?

We have a global variable myString which holds a string as its value. In the event handler function, we have a local variable value which holds a slash [ / ] as its value. We are using the includes[] method and ternary operator [ ? ] to check if myString contains value .

How do you use a forward slash in a string in Python?

When specifying a path, a forward slash [/] can be used in place of a backslash. Two backslashes can be used instead of one to avoid a syntax error. A string literal can also be used by placing the letter r before a string containing a backslash so it is interpreted correctly.

How do you print a forward slash in Python?

Backslash characters have a special meaning in Python, so to treat them as literal characters, we have to: escape each backslash with a second backslash. prefix the string with r to mark it as a raw string. use forward slashes in the place of backslashes in a path.

What is forward slash in regex in Python?

The documentation describes the syntax of regular expressions in Python. As you can see, the forward slash has no special function. The reason that [\w\d\s+-/*]* also finds comma's, is because inside square brackets the dash - denotes a range.

Chủ Đề