Negation in Python

The negation operator in Python is not. Therefore just replace your ! with not. For your example, do this: For your specific example (as Neil said in the comments), you don’t have to use the subprocess module, you can simply use os.mkdir() to get the result you need, with added exception handling goodness. Example: