'How to check a string contains 3 dots in python [duplicate]

eg: "ABC.sample.int.int01" like that, only want to check this string contains 3 dots. Thanks



Solution 1:[1]

You can check it like this, with count attribute of str in python. If it is equal to 3, then your strings actually contains exactly 3 dots.

if 'ABC.sample.int.int01'.count('.') == 3:
   ...
else:
   ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Amir reza Riahi